看板 NTUNL 關於我們 聯絡資訊
(1) 先開一個 .m file 建立 function (他會直接要求你存成 hysterisis.m): function dydt=hysterisis(t,x,u) global u; dydt=[u*x+x^3-x^5]; (2) 建立執行檔,一樣開一個 .m file: clear all; global u; for i=1:100 % setting the range of parameter "u" u=0.01*(i-50); % different initial conditions x0=[2.15]; y0=[0.04]; a0=[-2.15]; b0=[-0.04]; % solving odes by ode45 [t,x]=ode45(@hysterisis,0:0.1:10,x0); [t,y]=ode45(@hysterisis,0:0.1:10,y0); [t,a]=ode45(@hysterisis,0:0.1:10,a0); [t,b]=ode45(@hysterisis,0:0.1:10,b0); % defining the 100th step calculation of x as x* X(i)=x(100); Y(i)=y(100); A(i)=a(100); B(i)=b(100); % redefining the parameter "u" as "u(i)" U(i)=u; end subplot(2,2,1),plot(U,X) ylabel('x*') xlabel('u') subplot(2,2,2),plot(U,Y) ylabel('x*') xlabel('u') subplot(2,2,3),plot(U,A) ylabel('x*') xlabel('u') subplot(2,2,4),plot(U,B) ylabel('x*') xlabel('u') -- 先這樣啦,試試看就好。 -- " Morning's going past us and heading your way, my friend. You give it a chance, morning's going to bring you the reason you need, some purpose, because that's what the morning does." ==== Dean Knootz, SOLE SURVIOVOR ==== -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.91.18