

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is the MATLAB code for the Adams Bashfor predictor corrector method
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


i) ...................................................................................................................................... 1 ii) ..................................................................................................................................... 1 iii) .................................................................................................................................... 1 iv) .................................................................................................................................... 1 function ............................................................................................................................. 2
f = @(t,y) (texp(3t)-2*y); a = 0; b = 1; n = 5; alpha = 0; abm4(f,a,b,alpha,n);
f = @(t,y) (1+(t-y).^2); a = 2; b = 3; n = 5; alpha = 1; abm4(f,a,b,alpha,n);
f = @(t,y) (1+(y/t)); a = 1; b = 2; n = 5; alpha = 2; abm4(f,a,b,alpha,n);
f = @(t,y) (cos(2t)+sin(3t)); a = 0; b = 1; n = 5; alpha = 1; abm4(f,a,b,alpha,n);
Question 7
function [y t] = abm4(f,a,b,alpha,n)
h = (b-a)/n; t(1) = a; w(1) = alpha; fprintf(' t w\n'); fprintf('%5.4f %11.8f\n', t(1), w(1));
for i = 1: t(i+1) = t(i)+h; k1 = hf(t(i), w(i)); k2 = hf(t(i)+0.5h, w(i)+0.5k1); k3 = hf(t(i)+0.5h, w(i)+0.5k2); k4 = hf(t(i+1), w(i)+k3); w(i+1) = w(i)+(k1+2.0*(k2+k3)+k4)/6.0; fprintf('%5.4f %11.8f\n', t(i+1), w(i+1)); end
for i = 4:n t0 = a+ih; part1 = 55.0f(t(4),w(4))-59.0f(t(3),w(3))+37.0f(t(2),w(2)); part2 = -9.0f(t(1),w(1)); w0 = w(4)+h(part1+part2)/24.0; part1 = 9.0f(t0,w0)+19.0f(t(4),w(4))-5.0f(t(3),w(3))+f(t(2),w(2)); w0 = w(4)+h(part1)/24.0; fprintf('%5.4f %11.8f\n', t0, w0); for j = 1: t(j) = t(j+1); w(j) = w(j+1); end t(4) = t0; w(4) = w0; end end
Published with MATLAB® R2019b