11_13 Matlab Assignment 2

# 11_13 Matlab Assignment 2 - Matlab Assignment 2 Initial...

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

Matlab Assignment 2 Initial Guess of x = 1 Root found using initial guess of x = 1 is 1.41421356 CODE: x = 1; Tol = 0.0000001; count = 0; dx=1; %this is a fake value so that the while loop will execute f=-1; % because f(1)=-1 fprintf( 'step x dx f(x)\n' ) fprintf( '---- ----------- --------- ----------\n' ) fprintf( '%3i %12.8f %12.8f %12.8f\n' ,count,x,dx,f) xVec=x;fVec=f; while (dx > Tol || abs(f)>Tol) %note that dx and f need to be defined for this statement to proceed count = count + 1; fprime = 3*x^2- 2; xnew = x - (f/fprime); % compute the new value of x dx=abs(x-xnew); % compute how much x has changed since last step x = xnew; f = x^3 - 2*x; % compute the new value of f(x) fprintf( '%3i %12.8f %12.8f %12.8f\n' ,count,x,dx,f) end % This produces the following output: step x dx f(x) ---- ----------- --------- ---------- 0 1.00000000 1.00000000 -1.00000000 1 2.00000000 1.00000000 4.00000000 2 1.60000000 0.40000000 0.89600000 3 1.44225352 0.15774648 0.11551761 4 1.41501064 0.02724288 0.00319099 5 1.41421424 0.00079640 0.00000269 6 1.41421356 0.00000067 0.00000000 7 1.41421356 0.00000000 0.00000000

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.

## This note was uploaded on 11/26/2010 for the course MATH 110 taught by Professor Gordon during the Fall '10 term at NJIT.

### Page1 / 4

11_13 Matlab Assignment 2 - Matlab Assignment 2 Initial...

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

View Full Document
Ask a homework question - tutors are online