main17 - sd s % 2a % y''-2*y'+y=t*exp(t)-t % u1(t)=y(t) %...

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

% % Derek Rampal % 17 10/20 5.7 232 1(a), 2(a) Use the Runge-Kutta method of % order 4. Compute the actual values, the absolute errors and the number % of significant digits. % clear; c % 1a a1 = 0; b1 = 1; h1 =.2; ival1 = [1;1]; ffun = inline('[3*y(1)+2*y(2)-(2*t^2+1)*exp(2*t);4*y(1)+y(2)+(t^2+2*t- 4)*exp(2*t)]','t','y'); fact = inline('[1/3,-1/3,1;1/3,2/3,t^2]*exp([5;-1;2]*t)','t'); f [t1,onea] = rk4(ffun,a1,b1,h1,ival1); [m,n] = size(t1); [m1,n1]=size(onea); for i = 1:m oneaact(:,i) = fact(t1(i,1)); for j = 1:m1 [sd(j,i),abserr(j,i),relerr(j,i)] = sigdig(oneaact(j,i),onea(j,i)); end; end; e [t1';onea] oneaact abserr relerr
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sd s % 2a % y''-2*y'+y=t*exp(t)-t % u1(t)=y(t) % u1'(t)=u2(t)=y'(t) % u2'(t)=y''(t)=t*exp(t)-t+2*y'-y =t*exp(t)-t+2*u2(t)-u1(t) % a2 = 0; b2 = 1; h2 = .1; ival2 = [0;0]; gfun = inline('[y(2);t*exp(t)-t+2*y(2)-y(1)]','t','y'); gact = inline('1/6*t^3*exp(t)-t*exp(t)+2*exp(t)-t-2','t'); g [t2,twoa] = rk4(gfun,a2,b2,h2,ival2); [r,s] = size(t2); [r1,s1] = size(twoa); [ twoaact(:,1) = gact(t2(1,1)); t for i = 2:r twoaact(:,i) = gact(t2(i,1)); [sd2(1,i),abserr2(1,i),relerr2(1,i)] = sigdig(twoaact(1,i),twoa(1,i)); end; e time=t2' two_a=twoa(1,:) twoaact abserr2 relerr2 sd2...
View Full Document

Ask a homework question - tutors are online