MAT 581 HW chp 8 only

# MAT 581 HW chp 8 only - P 8.1.11 a For z= 1 or-1 p = 1 For...

This preview shows pages 1–3. Sign up to view the full content.

P 8.1.11 a) For z= 1 or -1; p = 1 For z= i or -i; p = i b) M-Files function [h] = WhichRoot(z0) if h= 'r1' ; [~,~,~,~,~]=GlobalNewton( 'fzp4m1' , 'dfzp4m1' ,0,z0+1,0.001,0.001,100); elseif h= 'r2' ; [~,~,~,~,~]=GlobalNewton( 'fzp4m1' , 'dfzp4m1' ,z0-1,0,0.001,0.001,100); elseif imag(z0) > 0 h= 'r3' ; [~,~,~,]=GlobalNewton2( 'fzp4m1' , 'dfzp4m1' ,0,z0+0.01,0.01,100); else h= 'r4' ; [~,~,~,]=GlobalNewton2( 'fzp4m1' , 'dfzp4m1' ,z0-0.01,0,0.01,100); end function [x,fx,nEvals] = GlobalNewton2(fName,fpName,a,b,tolx,MaxDiff) fa = feval(fName,a); fb = feval(fName,b); if fa*fb>0 disp( 'Initial interval not bracketing.' ) return end nEvals = 1; if a~=0 x=a; else x=b; end while fx = feval(fName,x); fpx = feval(fpName,x); x = x-fx/fpx nEvals = nEvals+1;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
end function [x,fx,nEvals,aF,bF] = GlobalNewton(fName,fpName,a,b,tolx,tolf,nEvalsMax) % [ x,fx,nEvals,aF,bF] = GlobalNewton(fName,fpName,a,b,tolx,tolf,nEvalsMax) % fName string that names a function f(x). % fpName string that names the derivative function f'(x). % a,b A root of f(x) is sought in the interval [a,b] % and f(a)*f(b)<=0. % tolx,tolf Nonnegative termination criteria. % nEvalsMax Maximum number of derivative evaluations. % % x An approximate zero of f. % fx The value of f at x. % nEvals The number of derivative evaluations required. % aF,bF The final bracketing interval is [aF,bF]. % % The iteration terminates as soon as x is within tolx of a true zero or % if |f(x)|<= tolf or after nEvalMax f-evaluations. fa
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

MAT 581 HW chp 8 only - P 8.1.11 a For z= 1 or-1 p = 1 For...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online