作者qazwsx80808 (ed)
看板MATLAB
标题[讨论] 想简化程式
时间Fri Sep 27 18:52:47 2013
老师刚刚派了个作业 以下是我刚打出来的程式
自己觉得打了好多行 想更简化 有请版上大大们能否帮忙一下
clear
dx=@(t,x) [-x(2)-100*x(1)*(x(1)^2+x(2)^2);x(2)-100*x(2)*(x(1)^2+x(2)^2)];
[t1,x1]=ode23(dx,[0,200],[-3.7,10]);
[t2,x2]=ode23(dx,[0,200],[-4.7,10]);
[t3,x3]=ode23(dx,[0,200],[-8,9]);
[t4,x4]=ode23(dx,[0,200],[-8,7]);
[t5,x5]=ode23(dx,[0,200],[-2.7,-8]);
[t6,x6]=ode23(dx,[0,200],[-0.4,-8]);
[t7,x7]=ode23(dx,[0,200],[3.6,-8]);
[t8,x8]=ode23(dx,[0,200],[5.9,-8]);
[t9,x9]=ode23(dx,[0,200],[10,-8]);
[t10,x10]=ode23(dx,[0,200],[0.5,10]);
plot(x1(:,1),x1(:,2),x2(:,1),x2(:,2),x3(:,1),x3(:,2),x4(:,1),
x4(:,2),x5(:,1),x5(:,2),x6(:,1),x6(:,2),x7(:,1),x7(:,2),
x8(:,1),x8(:,2),x9(:,1),x9(:,2),x10(:,1),x10(:,2));
axis([-8,10,-8,10])
xlabel('X1');
ylabel('X2');
title('u=100>0')
先感谢各位了
--
★ ☆ ▆▆▆ ★
深深掉进其他女人的陷阱里 ★ █ ◆ ▂
☆ 你还没回过神来 █▅▅
▓ ▃▃▍
▁▁ ▁▁ ▁▁ ▃▃█
▓ ▅▅ █ ▍
◢▃▃▃▃▃▃▃▃▃▃▃▃█▃▎█ ▎█ ▎ ▎▃▃▃▃ █ █▆▍
☆
◥ ★ █ ▎█▁▎█▁▎ ▎ ★ █▆
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.108.212
1F:→ math99:help cell 09/27 20:47
2F:推 alamabarry:一样的东西 何不用回圈去写呢 配合矩阵 09/28 04:37
3F:推 sunev:用hold on比较快。 09/28 07:08
XDDD 到最後 还是不会用hold on来写....
後来写出来的
clear
I1=repmat([-1;1],10,1);
I2=reshape([1;1]*(2:2:20),[],1);
dx=@(t,x)I1.*x(I2)-100*x.*(x(I2-1).^2+x(I2).^2);
[t,x]=ode23(dx,[0,200],[-3.7,10,-4.7,10,-8,9,-8,7,-2.7,
-8,-0.4,-8,3.6,-8,5.9,-8,10,-8,0.5,10]);
plot(x(:,1:2:end),x(:,2:2:end))
xlabel('X1');
ylabel('X2');
title('u=100>0')
※ 编辑: qazwsx80808 来自: 220.129.36.45 (09/28 22:12)