Newton_Raphson - f=[f1 f2]'; fprintf('\n %d %8.7f %8.7f...

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

View Full Document Right Arrow Icon
function Newton_Raphson(x1,x2,iter) %Problem 12.7 i=0; x1_old=0; x2_old=0; ea1=0; ea2=0; fprintf('\n'); disp('iteration y x ea2 ea1'); x=[x1 x2]'; while(1) f1_x1=1; f2_x1=1+5*x2; f1_x2=2*x2-1; f2_x2=5*x1-2*x2; J=[f1_x1 f1_x2; f2_x1 f2_x2]; f1=x1+x2^2-x2-0.5; f2=x1+5*x2*x1-x2^2;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: f=[f1 f2]'; fprintf('\n %d %8.7f %8.7f %5.4f %6.3f\n', i, x1,x2,ea1,ea2); x=x-J\f; x1=x(1,1); x2=x(2,1); ea1=abs((x1-x1_old)/x1)*100; ea2=abs((x2-x2_old)/x2)*100; i=i+1; x1_old=x1; x2_old=x2; if i==iter+1 break; end end...
View Full Document

Ask a homework question - tutors are online