{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

problem4_21 - end L=[H D E fprintf step size finite...

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

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

Unformatted text preview: end L=[H' D' E']'; fprintf(' step size finite difference true error\n'); fprintf('%14.10f %16.14f %16.13f\n',L); loglog(H,E),xlabel('Step Size'), ylabel('Error') title('Plot of Error Versus Step Size'); format short end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online