Abm

download Abm

If you can't read please download the document

description

predictor

Transcript of Abm

function [] = abm(f,a,b,ya,n)f=inline('t*exp(3*t)-2*y');a=0;b=1;ya=0;h=0.1;n = (b - a) / h;h24 = h / 24;y(1,:) = ya;t(1) = a;y1(1,:) = ya;m = min(3,n);err(1)=abs(y1(1)-y(1,:));for i = 1 : m % Runge-Kutta orde 4 t(i+1) = t(i) + h; s(i,:) = f(t(i), y(i,:)); s2 = f(t(i) + h / 2, y(i,:) + s(i,:) * h /2); s3 = f(t(i) + h / 2, y(i,:) + s2 * h /2); s4 = f(t(i+1), y(i,:) + s3 * h); y(i+1,:) = y(i,:) + (s(i,:) + s2+s2 + s3+s3 + s4) * h / 6;end;for i = m + 1 : n s(i,:) = f(t(i), y(i,:)); y(i+1,:) = y(i,:) + (55 * s(i,:) - 59 * s(i-1,:) + 37 * s(i-2,:) - 9 * s(i-3,:)) * h24; % predictor t(i+1) = t(i) + h; y(i+1,:) = y(i,:) + (9 * f(t(i+1), y(i+1,:)) + 19 * s(i,:) - 5 * s(i-1,:) + s(i-2,:)) * h24; % correctorend;for i = 1 : n y1(i+1)=1/(25*exp(2*t(i+1))) + (exp(3*t(i+1))*(5*t(i+1) - 1))/25;err(i+1)=abs(y1(i+1)-y(i+1,:))end;figure (1)plot(t, err,'o-r','linewidth',2)hold ongrid onxlabel('iterasi')ylabel('error')legend ('error A-M') figure (2)plot(t, y1,'o-r',t, y,'o-b','linewidth',2)hold ongrid onxlabel('nilai t')ylabel('nilai y')legend ('nilai aktual','nilai A-M')