hw3_solutions

hw3_solutions - CS 257/MATH 257 Numerical Methods -...

Info iconThis preview shows pages 1–2. 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: CS 257/MATH 257 Numerical Methods - Homework 3 September 21, 2007 1. [1pt] Section 3.2 #15 Solution: The first iteration of Newtons 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 Newtons Method to be turned in. Use the following function declaration. It will be helpful in the next problem. You dont need to include the comments in your file. function [x,xs]=newton(f, fp, x0, n_max) % newton Newtons 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 = x-values during iteration Solution: function [x,xs]=newton(f, df, x0, n_max) % newton Newtons 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 = x-values 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 x-values 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

Page1 / 5

hw3_solutions - CS 257/MATH 257 Numerical Methods -...

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

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