Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ydot=myfun(t,y,a)
- S1 = 2 *a* 2 * y(2) - 2 * 3 * y(1)*y(1);
- S2 = 3 * y(1)*y(1) + a - 5 * y(2);
- ydot = [S1; S2];
- y_0=[0,0];
- %[t,y]=ode45(@myfun,[0:0.1:Tfinal],y_0);
- and run following with nested myfun function:
- %function events=events_in_Matlab(a)
- dt=0.01;
- T=0:dt:30;
- y_0=[0 0];
- Y=zeros(length(T),length(y_0));
- %t=0 to t=10, pass parameter a=0 to add to ODEs
- a=0;
- [~,Y(1:10/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(1:10/dt+1),y_0);
- %t=10 to t=20, pass parameter a=10 to add to ODEs
- a=10;
- [~,Y(10/dt+1:20/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(10/dt+1:20/dt+1),
- Y(10/dt+1,:));
- %t=20 to t=30, pass parameter a=20 to add to ODEs
- a=20;
- [~,Y(20/dt+1:end,:)]=ode45(@(t,y)myfun(t,y,a),T(20/dt+1:end),(20/dt+1,:));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement