{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework 2

# Homework 2 - >%This program uses Newtons Method to find the...

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

>> %This program uses Newtons Method to find the root Po of our function f% >> Po = 1.5; %Since [1,2], choose 1.5% >> f = inline ('exp(x) + 2^-x+2*cos(x)-6') f = Inline function: f(x) = exp(x) + 2^-x+2*cos(x)-6 >> g= inline ('exp(x) - 2^(-x)*log(2)-2*sin(x)') g = Inline function: g(x) = exp(x) - 2^(-x)*log(2)-2*sin(x) >> %f is the original function and g is the derivative of f% >> i=1; >> max =4; %Max is the maximum number of iterations% >> while i <= max p = Po-f(Po)/g(Po); i=i+1; Po=p format long end Po =1.9565 Po =1.84153306104206 Po =1.82950601320365 Po =1.82938361449417

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

View Full Document
>> %This program uses Newtons Method to find the root Po of our function f% >> Po=1.4; %Initial guess is 1.4% >> f = inline ('log (x-1) + cos(x-1)') f = Inline function: f(x) = log (x-1) + cos(x-1) >> g = inline ('1/(x-1) - sin(x-1)') g = Inline function: g(x) = 1/(x-1) - sin(x-1) >> %g is the derivative of f% >> i=1; >> max = 3; %Max is the maximum number of iterations% >> while i <= max p = Po-f(Po)/g(Po); i=i+1; Po=p format long end Po =1.39773983531443 Po =1.39774847583162 Po =1.39774847595875
>> %This program uses Newtons Method to find the root Po of our function f% >> %p1 and p2 are initial guesses% >> %p1 will be within the interval 2 and 3% >> %p2 will be within the interval 3 and 4% >> p1 =2.5; >> p2=3.5; >> f = inline('2*x*cos(2*x)-(x-2)^2') f = Inline function: f(x) = 2*x*cos(2*x)-(x-2)^2 >> g = inline('2*cos(2*x)-4*x*sin(2*x)-2*x+4')%g is the derivative of f% g = Inline function: g(x) = 2*cos(2*x)-4*x*sin(2*x)-2*x+4 >> max =3; %max is maximum number of iterations% >> i=1; >> while i <= max pa = p1-f(p1)/g(p1); %pa is when working in p1%

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern