{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

rk4 - h=(b-a/N t=a t(1)=t y=alpha y(1 = y y(1 = alpha t(1 =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
C:\matlabR12\work\rk4.m December 10, 2010 Page 1 3:52:29 PM function [t,y] = rk4(fofty,a,b,alpha,N) % function w = rk2(fofty,a,b,alpha,N) is a Matlab program to solve the IVP % by using Rung-Kuta of order four method. % Inputs: % fofty is a name of m-file which evaluates the function f(t,y). % a and b is the endpoints of the interval [a,b]; % alpha is the initial value. % N is an integer represent the number of subintervals.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: h=(b-a)/N; t=a; t(1)=t; y=alpha; y(1,:) = y'; y(1) = alpha; t(1) = a; % the main loop for calculating the values of y. for i=1:N, f1 = h*feval(fofty,t,y); f2 = h*feval(fofty,t+h/2, y+f1/2); f3 = h*feval(fofty,t+h/2, y+f2/2); f4 = h*feval(fofty,t+h, y+f3); y = y+(f1+2*f2+2*f3+f4)/6; t = t+h; end t(i+1) = t; y(i+1,:)=y';...
View Full Document

{[ snackBarMessage ]}