assign6.sol

# Assign6.sol - function which implements Newton’s method fp=funcfp(x0 flag=0 if the derivative is zero end the program if(fp==0 disp(’fp = 0’

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

ASE 211 Homework 6 - Solution 1. Consider the nonlinear function f ( x ) = 3 x +3 x 5 5 - 2 . Suppose we want to ﬁnd a positive real root for this function. (a) Take 4 iterations of the bisection method by hand starting with the initial interval [-1,1]. i. a b x= ( a + b ) / 2 f ( a ) f ( b ) f ( x ) -1 1 0 -5.6 1.6 -2 0 1 0.5 -2 1.6 -0.4812 0.5 1 0.75 -0.4812 1.6 0.3924 0.5 0.75 0.625 -0.4812 0.3924 -0.0678 0.625 0.75 0.6875 -0.0678 0.3924 0.1547 (b) Apply 4 iterations of Newton’s method by hand with initial guess x 0 = 0 . i. x 1 f ( x 1 ) 0 -2 0.6667 0.079 0.6447 8.32e-4 0.6444 8.98e-8 0.6444 1.33e-15 (c) Apply 4 iterations of the Secant method by hand with initial guesses x 0 = 0 , x 1 = 1 . i. x 1 f ( x 1 ) 0 -2 1 1.6 0.5556 -0.3016 0.626 -0.0642 0.6451 0.0023 0.6444 -5.74e-9 (d) Which of these methods converges fastest? Rank the methods. Newton converges the fastest followed by Secant then Bisection . 2. Write a matlab code newton.m which implements Newton’s method (as discussed in class). Test your code on the function in problem 1 with initial guess x 0 = 0 . Take your tolerances f tol and x tol to be 10 - 5 and set the maximum number of iterations to 100.

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

View Full Document
function newton(x0,xtol,ftol,maxiter)

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.

Unformatted text preview: % function which implements Newton’s method % fp=funcfp(x0); flag=0; % if the derivative is zero, end the program if (fp==0) disp(’fp = 0’) flag=1; end if (flag==1) break end % x1=x0-funcf(x0)/fp; k=0; f0=1; f1=0; while (abs(x1-x0) > xtol & k <= maxiter & abs(f1-f0)>ftol) x0=x1; fp=funcfp(x0); f=funcf(x0); if (fp ==0) disp (’fp = 0’) flag=1; end % if the derive is zero, end the program if (flag==1) break end k=k+1; x1=x0-f/fp; f0=f1; f1=f; end if (k<=maxiter) display(’solution converges’) k x1 f1 dx=x1-x0 else disp(’solution did not converge after 100 iterations’) end function y=funcf(x) y=3*x+3*(x^5)/5-2; function y=funcfp(x) y=3+3*x^4; >> xtol=1e-5 xtol = 1.0000e-05 >> ftol=1e-5 ftol = 1.0000e-05 >> maxitr=100 maxitr = 100 >> x0=0 x0 = >> newton(x0,xtol,ftol,maxitr) solution converges k = 3 x1 = 0.6444 f1 = 8.9872e-08 dx =-2.5551e-08...
View Full Document

## This note was uploaded on 03/20/2008 for the course ASE 211 taught by Professor N/a during the Spring '08 term at University of Texas at Austin.

### Page1 / 4

Assign6.sol - function which implements Newton’s method fp=funcfp(x0 flag=0 if the derivative is zero end the program if(fp==0 disp(’fp = 0’

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

View Full Document
Ask a homework question - tutors are online