Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function [t,y]=RK(fun,tspan,y0,n,A,b,c)
  2.  
  3. h=(tspan(2)-tspan(1))/n;
  4. y(:,1)=y0;
  5. t(1)=tspan(1);
  6. s=length(b);
  7. for j=1:n
  8. $ k(:,1)=feval(fun,t(j),y(:,j));
  9. for i=2:s
  10. k(:,i)=feval(fun,t(j)+c(i)*h,y(:,j)+h*k(:,1:i-1)*A(i,1:i-1)');
  11. end
  12. end
  13. 2. function dy=pred_prey(t,y)
  14. function s=cos(x)
  15. k=1;
  16. a=2/3;
  17. d=4/3;
  18. r(t)=int(s(x^2),x,0,t);
  19. mu(t)=13/20-(3/5)*exp(-(3/x));
  20. dy(1)=(y(1)+k)*r(t)-a*y(1)*y(2);
  21. dy(2)=-mu(t)*y(2)+d*y(1)*y(2);
  22. dy=dy';
  23. 3. function []=driver_pred_prey()
  24. close all
  25. tspan=[0 100];
  26. n=1000;
  27. fun='pred_prey';
  28. y0=[0 -1]';
  29. A=[0 0 0 0; 1/2 0 0 0 ; 0 1/2 0 0; 0 0 1 0];
  30. b=[1/6 1/3 1/3 1/6]';
  31. c=[0 1/2 1/2 1]';
  32. $$[t,y]=RK('pred_prey', tspan, y0, n, A, b, c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement