Advertisement
Guest User

lab7mac

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function [t,y]=runge_hutta(inter,y0,n)
  2. t(1)=inter(1);
  3. y(1)=y0;
  4. h=(inter(2)-inter(1))/n;
  5. for i=1:n
  6. t(i+1)=t(i)+h;
  7. y(i+1)=rungestep(t(i),y(i),h);
  8. end
  9. plot(t,y)
  10.  
  11. function y=rungestep(t,y,h)
  12. s1=ydot(t,y);
  13. s2=ydot(t+h*y/2+h*s1/2);
  14. s3=ydot(t+h*y/2+h*s2/2);
  15. s4=ydot(t+h*y+h*s3);
  16. y=y+h(s1+2*s2+2*s3+s4)/6;
  17.  
  18. function z=ydot(t,y)
  19. z=t^3/y^2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement