Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

f(x) = ((x 1)^2) e^x Apply the Newton iteration formula to f(x) using the following code. Use the default convergence tolerance of 10^6 and record

f(x) = ((x 1)^2) e^x

Apply the Newton iteration formula to f(x) using the following code. Use the default convergence tolerance of 10^6 and record the iterations starting from an initial guess of x0 = 2.

Code is as follows:-

function [root, iter, xlist] = newton( func, pfunc, xguess, tol, mult ) %NEWTON Newton's method for solving a nonlinear equation. % % Sample usage: % [root, niter, xlist] = newton( func, pfunc, xguess, [tol], [mult] ) % % Input: % func - function to be solved % pfunc - derivative of 'func' % xguess - initial guess at root % tol - convergence tolerance (OPTIONAL, defaults to 1e-6) % mult - factor for multiple roots (OPTIONAL, defaults to 1.0) % % Output: % root - final estimate of the root % niter - number of iterations until converged % xlist - list of iterates, an array of length 'niter' % First, do some error checking on parameters. if nargin < 3 fprintf(1, 'NEWTON: must be called with at least three arguments' ); error( 'Usage: [root, niter, xlist] = newton( func, pfunc, xguess, [tol], [mult] )' ); end if nargin < 4, tol = 1e-6; end if nargin < 5, mult = 1.0; end % fcnchk(...) converts function parameters to the correct type % to allow evaluation by feval(). func = fcnchk( func ); pfunc= fcnchk( pfunc ); x = xguess; fx = feval( func, x ); fpx = feval( pfunc, x ); if( fx == 0 | fpx == 0 ) error( 'NEWTON: both f and f'' must be non-zero at the initial guess' ); end xlist= [ x ]; done = 0; iter = 0; while( ~done ) x0 = x; x = x0 - fx / fpx * mult; fx = feval( func, x ); fpx = feval( pfunc, x ); if( abs(x-x0) < tol ) % absolute tolerance on x done = 1; else xlist = [ xlist; x ]; % add to the list of x-values iter = iter + 1; end end root = x; %END newton.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions