error_421 - E(i,1) = abs(dftrue-D(i,1)); end e loglog (H,...

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

View Full Document Right Arrow Icon
%Problem 4.21 % function error_421(x,n) f format long; f h = 1; h H = zeros(10,1); D = zeros(10,1); E = zeros(10,1); E dftrue = dfunc(x); H(1,1) = h; D(1,1) = (func(x+h) - func(x-h))/(2*h); E(1,1) = abs(dftrue-D(1,1)); E for i = 2:n h = h/10; H(i,1) = h; D(i,1) = (func(x+h) - func(x-h))/(2*h);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: E(i,1) = abs(dftrue-D(i,1)); end e loglog (H, E) l title ('Plot of Error Versus Step Size') t xlabel ('Step Size') ylabel ('Error') y end e function new1 = func(x) f new1 = cos(x); end e function new2 = dfunc(x) f new2 = -sin(x); end...
View Full Document

Ask a homework question - tutors are online