{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw06_p04 - if(fid4< 0 error'could not open...

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

clc clear format long f x0 = input('Initial guess in a row vector form: '); xold = x0; tolerance = input('tolerance:'); n = 1; n [xnew(1), xnew(2)] = hw06_p04_newton( xold(1), xold(2) ); disp(xnew); d while ( abs( xnew(1) - xold(1) ) > tolerance | abs( xnew(2) - xold(2) ) > tolerance ) xold = xnew; [xnew(1), xnew(2)] = hw06_p04_newton( xold(1), xold(2) ); n = n + 1; end % open file fid4 = fopen('hw06_p04_answer.txt','a'); % 'wt' means "write text"
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (fid4 < 0) error('could not open file "hw06_p04_answer.txt"'); end; fprintf(fid4,'\n\nInitial guesses are \n'); for i = 1:length(x0) fprintf(fid4,'%15.5f\n',x0(i)); end fprintf(fid4,'Tolerance = %10.3e\n',tolerance); fprintf(fid4,'Number of iteration = %10d\n',n); fprintf(fid4,'Solutions are \n'); for i = 1:length(xnew) fprintf(fid4,'%15.5f\n',xnew(i)); end fclose(fid4); disp(n) d...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online