24小时热门版块排行榜    

CyRhmU.jpeg
南方科技大学公共卫生及应急管理学院2026级博士研究生招生报考通知(长期有效)
查看: 742  |  回复: 14
当前主题已经存档。

monitor2885

至尊木虫 (职业作家)

队长

function test
t=0:10;
[t,y]=ode45(@ivpodefun,t,[0 2]);
figure(2)
plot(t,y,'bo-')
function dydt=ivpodefun(t,y,u)
a=[1;2;3;4;5];b=[6;7;8;9;10];
for i=1:1:5
    if ((i-1)*2<=t & t<=2*i)
u1=a(i);
u2=b(i);
    end
end
figure(1)
plot(t,u1,'ro');hold on
plot(t,u2,'b^');
xlim([0 10])
ylim([0 10])
dydt=zeros(2,1);
dydt(1)=u2*y(2);
dydt(2)=u1*(1-y(1)^2)*y(2)-y(1);

还是疯狂刷屏呀!
Retirement
11楼2009-10-12 23:17:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

★ ★ ★ ★ ★ ★ ★ ★ ★
wuguocheng(金币+3,VIP+0): 谢谢参与 10-13 07:59
monitor2885(金币+6,VIP+0):如何能在workspace里面显示出u1和u2,这两个参数要存储住 10-13 11:20
提出来放到主函数里面不就是了,为什么非要在微分函数里画呢?

function test
clear
clc
global a b
a=[1;2;3;4;5];b=[6;7;8;9;10];
t=0:0.1:10;
[t,y]=ode45(@ivpodefun,t,[0 2]);
figure(2)
plot(t,y(:,1),'ro-',t,y(:,2),'b^-')
legend ('y_1','y_2')
legend boxoff
% figure (1)
for i=1:5
    for j=1:length(t)
        if (i-1)*2<=t(j) && t(j)<=2*i
            u1(j)=a(i);
            u2(j)=b(i);
        end
    end
end
figure(1)
plot(t,u1,'ro');hold on
plot(t,u2,'b^');
xlim([0 10])
ylim([0 10])
legend ('u_1','u_2','Location','SouthEast')
legend boxoff

function dydt=ivpodefun(t,y)
global a b
for i=1:5
    if (i-1)*2<=t && t<=2*i
        u1=a(i);
        u2=b(i);
    end
end
dydt=zeros(2,1);
dydt(1)=u2*y(2);
dydt(2)=u1*(1-y(1)^2)*y(2)-y(1);

[ Last edited by change0618 on 2009-10-12 at 23:47 ]
12楼2009-10-12 23:36:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师


monitor2885(金币+1,VIP+0): 10-13 15:19
你要干什么?

可以把他们保存下来
save u.mat u1 u2
然后就生成一个u.mat文件,点击打开,workspace里就有了
13楼2009-10-13 12:01:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师


monitor2885(金币+1,VIP+0): 10-13 15:19
或者你把主函数写成
function [u1,u2]=test(a , b , t)
......
......
.....
然后在命令窗口里输入:
a=[1;2;3;4;5];
b=[6;7;8;9;10];
t=0:0.05:10;
[u1,u2]=test(a, b ,t)
就出来了

[ Last edited by change0618 on 2009-10-13 at 12:26 ]
14楼2009-10-13 12:10:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师


monitor2885(金币+1,VIP+0): 10-13 15:19
或者你把主函数变成script命令函数(去掉function test),子函数ivpodefun单独保存为函数文件,运行主函数也会出来的

[ Last edited by change0618 on 2009-10-14 at 17:57 ]
15楼2009-10-13 12:14:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 monitor2885 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见