[討論] 想簡化程式

看板MATLAB作者 (ed)時間12年前 (2013/09/27 18:52), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
老師剛剛派了個作業 以下是我剛打出來的程式 自己覺得打了好多行 想更簡化 有請版上大大們能否幫忙一下 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

09/27 20:47, , 1F
help cell
09/27 20:47, 1F

09/28 04:37, , 2F
一樣的東西 何不用迴圈去寫呢 配合矩陣
09/28 04:37, 2F

09/28 07:08, , 3F
用hold on比較快。
09/28 07:08, 3F
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)
文章代碼(AID): #1IHME3Rc (MATLAB)