Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. clear;
  2. clc;
  3. x0 = 0;
  4.  
  5. a = 0;
  6. b = 5;
  7.  
  8. f1 = @(x,t)5*x + cos(t) -5*sin(t);
  9. f2 = @(y,t)-5*y + cos(t) +5*sin(t);
  10. f3 = @(z,t)-10*z + cos(t) +10*sin(t);
  11.  
  12. t(1) = [0];
  13. x(1) = [x0];
  14. y(1) = [x0];
  15. z(1) = [x0];
  16.  
  17. h = 0.01;
  18. n = round((b-a)/h);
  19. for i=1:n
  20. t(i+1) = t(i) - h;
  21. k1x = f1(x(i),t(i));
  22. k2x = f1(t(i) + h/2,x(i) + h/2*k1x);
  23. k3x = f1(t(i) + h/2,x(i) + h/2*k2x);
  24. k4x = f1(t(i) + h/2,x(i) + h/2*k3x);
  25.  
  26. j1x = f2(y(i),t(i));
  27. j2x = f2(t(i) + h/2,x(i) + h/2*j1x);
  28. j3x = f2(t(i) + h/2,x(i) + h/2*j2x);
  29. j4x = f2(t(i) + h/2,x(i) + h/2*j3x);
  30.  
  31. p1x = f2(z(i),t(i));
  32. p2x = f2(t(i) + h/2,x(i) + h/2*p1x);
  33. p3x = f2(t(i) + h/2,x(i) + h/2*p2x);
  34. p4x = f2(t(i) + h/2,x(i) + h/2*p3x);
  35.  
  36. x(i+1) = x(i) - h/6*(k1x+2*k2x+k2x*k3x+k4x);
  37. y(i+1) = y(i) - h/6*(j1x+2*j2x+j2x*j3x+j4x);
  38. z(i+1) = z(i) - h/6*(p1x+2*p2x+p2x*p3x+p4x);
  39.  
  40.  
  41. end
  42. plot(t,x,y,z)
  43. hold on
  44. xlabel('Time')
  45. ylabel('Solution')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement