Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function ydot=myfun(t,y,a)
  2.  
  3. S1 = 2 *a* 2 * y(2) - 2 * 3 * y(1)*y(1);
  4. S2 = 3 * y(1)*y(1) + a - 5 * y(2);
  5. ydot = [S1; S2];
  6. y_0=[0,0];
  7. %[t,y]=ode45(@myfun,[0:0.1:Tfinal],y_0);
  8.  
  9.  
  10. and run following with nested myfun function:
  11.  
  12.  
  13. %function events=events_in_Matlab(a)
  14. dt=0.01;
  15. T=0:dt:30;
  16. y_0=[0 0];
  17. Y=zeros(length(T),length(y_0));
  18.  
  19.  
  20. %t=0 to t=10, pass parameter a=0 to add to ODEs
  21. a=0;
  22. [~,Y(1:10/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(1:10/dt+1),y_0);
  23. %t=10 to t=20, pass parameter a=10 to add to ODEs
  24. a=10;
  25. [~,Y(10/dt+1:20/dt+1,:)]=ode45(@(t,y)myfun(t,y,a),T(10/dt+1:20/dt+1),
  26. Y(10/dt+1,:));
  27. %t=20 to t=30, pass parameter a=20 to add to ODEs
  28. a=20;
  29.  
  30. [~,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