{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
>> %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
Image of page 1

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

View Full Document Right Arrow Icon
>> %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
Image of page 2
>> %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%
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern