This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 257/MATH 257 Numerical Methods  Homework 3 September 21, 2007 1. [1pt] Section 3.2 #15 Solution: The first iteration of Newton’s method is: x 1 = x f ( x ) f ( x ) In this case x = 1, f ( x ) = 1, and f ( x ) = 3 x 2 1 = 2. Therefore x 1 = 1 / 2. 2. [1pt] Write an implementation of the Newton’s Method to be turned in. Use the following function declaration. It will be helpful in the next problem. You don’t need to include the comments in your file. function [x,xs]=newton(f, fp, x0, n_max) % newton Newton’s Method to find a root of the scalar equation f(x) = 0 % % Synopsis: [x,xs] = newton(f,fp,x0,n_max) % % Input: f,fp = function pointers that returns f(x) and f’(x) % x0 = initial guesses % n_max = number of iterations. % % Output: x = the root of the function % xs = xvalues during iteration Solution: function [x,xs]=newton(f, df, x0, n_max) % newton Newton’s Method to find a root of the scalar equation f(x) = 0 % % Synopsis: [x,xs] = newton(f,fp,x0,n_max) % % Input: f,fp = function pointers that returns f(x) and f’(x) % x0 = initial guesses % n_max = number of iterations. % % Output: x = the root of the function % xs = xvalues during iterat xs = [x0]; x = x0; for n = 1:n_max fx=feval(f,x); %evaluate f(x) dfx=feval(df,x); %evaluate f’(x) x = x  fx/dfx; xs = [xs;x]; %store the xvalues end 3. [2pt] Consider the following polynomial x 4 12 x 3 + 30 x 2 + 100 x 375 This polynomial has two roots: 3 and 5....
View
Full Document
 Fall '05
 ThomasKerkhoven
 Derivative, Secant method, Rootfinding algorithm

Click to edit the document details