DeGracia_Miguel_19481379_Section22_Lab11

DeGracia_Miguel_19481379_Section22_Lab11 - %% Miguel De...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %% Miguel De Gracia. 19481379. Section 22. Lab Assignment 11. % %% Problem 1a % type my_bisection t fh=@(x)x^2+x-2; f [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'a',100) [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'r',100) [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'f',100) E = fzero(fh,-2) E [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'a',100) [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'r',100) [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'f',100) E = fzero(fh,1) E fh = @(x)cos(x)-sin(x); f [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'a',100) [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'r',100) [root,rhist,niter,error] = my_bisection(fh,-5,0,1e-5,'f',100) E = fzero(fh,-2) E [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'a',100) [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'r',100) [root,rhist,niter,error] = my_bisection(fh,0,5,1e-5,'f',100) E = fzero(fh,1) E %% Problem 1b % fh = @(x)x^2+x-2; [root1,rhist1,niter1,error1] = my_bisection(fh,0,-50,1e-14,'a',100) semilogy(1:niter1,abs(rhist1-root1)),xlabel('n'),ylabel('abs(xn-x*)') s %% Problem 1c % P = polyfit(abs(rhist(1:end-1)-root),abs(rhist(2:end)-root),1); C = P(1) C %% Problem 2 % fnew = @(x) -x^cos(x)+5*sqrt(x)-exp(2*sin(x))-x^2+3; ezplot(fnew,[0 pi]) [root,rhist,niter,error] = my_bisection(fnew,0,1.5,1e-4,'f',100) fzero(fnew,1) [root,rhist,niter,error] = my_bisection(fnew,1.5,pi,1e-4,'f',100) fzero(fnew,2) f %% Problem 3a % type my_newton t fh = @(x)x^2+x-2; dfh = @(x)2*x+1; d [root,rhist,niter,error] = my_newton(fh,dfh,-1,1e-5,'a',100) [root,rhist,niter,error] = my_newton(fh,dfh,-1,1e-5,'r',100) [root,rhist,niter,error] = my_newton(fh,dfh,-1,1e-5,'f',100) E = fzero(fh,-2) E [root,rhist,niter,error] = my_newton(fh,dfh,0,1e-5,'a',100) [root,rhist,niter,error] = my_newton(fh,dfh,0,1e-5,'r',100) [root,rhist,niter,error] = my_newton(fh,dfh,0,1e-5,'f',100)...
View Full Document

Page1 / 6

DeGracia_Miguel_19481379_Section22_Lab11 - %% Miguel De...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online