{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lab10 - Riti Gupta/20249537 Section 22/Lab10 1.a > fplot(x...

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

Riti Gupta/20249537 Section 22/Lab10 1.a.) >> fplot(@(x) 2*sin(2*x^3)+1.25*x-0.5,[-10 10 -10 10]) b.) A = @(x) 2*sin(2*x^3)+1.25*x-0.5 B = [] for i= -3:.1:3 C = fzero(A, i); B = [B, C]; end roots: 3072, 1.2258, 1.4095, 1.7330, 1.7921. 2. function [root_aprox]=bisection(fh1, x, eps, iter) x1=x(1); x2=x(2); m=(x1+x2)/2; for i=1:iter while abs(fh1(m)) > eps m=(x1+x2)/2; if fh1(m)*fh1(x1)<0 x2=m; m=(x1+x2)/2; m fh1(m) elseif fh1(m)*fh1(x2)<0 x1=m; m=(x1+x2)/2; m fh1(m) end -10 -8 -6 -4 -2 0 2 4 6 8 10 -10 -8 -6 -4 -2 0 2 4 6 8 10

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

View Full Document
end end end >> [email protected](x) 2*sin(2*x^3)+1.25*x-0.5 fh1 = @(x)2*sin(2*x^3)+1.25*x-0.5 >> bisection(fh1, [0,2],.0001,100) m = 0.5000 ans = 0.6198 m = 0.2500 ans = -0.1250 m = 0.3750 ans = 0.1793 m = 0.3125 ans = 0.0126 m = 0.2813 ans = -0.0595
m = 0.2969 ans = -0.0243 m = 0.3047 ans = -0.0061 m = 0.3086 ans = 0.0032 m = 0.3066 ans = -0.0014 m = 0.3076 ans = 8.9293e-004 m = 0.3071 ans = -2.7007e-004 m =

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

View Full Document
0.3074 ans = 3.1121e-004 m = 0.3073 ans = 2.0513e-005 3. a.) function [root_aprox]=newton1(fh1, df1, x, eps, iter) root_aprox=x; for i=1:iter; while abs(fh1(x))>eps x=x-(fh1(x)/df1(x)); root_aprox=x fh1(root_aprox) end end end >> [email protected](x) 2*sin(2*x^3)+1.25*x-0.5 fh1 = @(x)2*sin(2*x^3)+1.25*x-0.5 >> [email protected](x) 12*x^2*cos(2*x^3)+1.25 df1 = @(x)12*x^2*cos(2*x^3)+1.25 >> newton1(fh1,df1,1,0.0001,100) root_aprox = 1.6861 ans = 1.2847 root_aprox = 1.7257
ans = 0.1491 root_aprox = 1.7324 ans = 0.0107 root_aprox = 1.7330 ans = 8.1512e-005 ans = 1.7330 b.) function

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Lab10 - Riti Gupta/20249537 Section 22/Lab10 1.a > fplot(x...

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

View Full Document
Ask a homework question - tutors are online