Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to find a number r such that r^2 = e^r. Of course, this is equivalent to

ID: 3665860 • Letter: I

Question

I want to find a number r such that r^2 = e^r. Of course, this is equivalent to either r = -e^r/2 or r = +e^r/2 (which one?). How can I use the Newton's method to find r? Propose a function f whose root coincides with the number r that I want to find. Propose an initial approximation x_0 that guarantees convergence (explain your choice of x_0). Solutions to the following problems should consist of program codes, computed results, and short write-ups. In the write-up, discuss the results you have obtained and explain them from the numerical point of view. Use SINGLE PRECISION ONLY. Insert COM­MENTS in your programs. Implement Newton's iteration and test it for 3 nonlinear equations (of your choice) for which you know the roots. Make sure that your algorithm does not perform more than 20 iterations, and print both the true error |e_n| = |r - x_n| and its empirical estimate /en/-~|f(x_n)/f(x_n)| As always provide a short description of the equations and a short discussion of obtained results (e.g., are the empirical error estimates close to the true errors?), with the source- code, and printed computer results.

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<math.h>

#define EPS 0.000001

#define MAXIT 20

#define F(x) (x)*(x)*(x)+(x)*(x)-3*(x)-3

#define FD(x) 3*(x)*(x)+2*(x)-3

void main(){
clrscr();
int count;
float x0, xn, fx, fdx, fxn;
cout<<" Enter non linear equation ;
cout<<endl<<"x^3+x^2-3x-3";
cout<<endl<<"Enter the initial value of x:";
cin>>x0;
count=1;
begin:
  fx=F(x0);
  fdx=FD(x0);
  xn=x0-fx/fdx;
  if (fabs((xn-x0)/xn) < EPS){
cout<<"Approximate Root: "<<xn<<endl;
fxn =F(xn);
cout<<"Functional Value: "<<fxn<<endl;
cout<<"No. of Iterations: "<<count<<endl;
  }
  else{
x0=xn;
count=count+1;
if(count<MAXIT){
   goto begin;
}
else{
cout<<"SOLUTION DOES NOT CONVERGE!!"<<endl;
cout<<"Iterations: "<<MAXIT<<endl;
}
  }
getch();
}

Sample Output: Here the sample non linear equation

x^3+x^2-3x-3

Enter the initial value of x:2

Approximate Root: 1.73205

Functional Value: -2.94213e-07

No. of Iterations: 4

The Newton-Raphson Iteration

Let x0 be a good estimate of r and let r = x0 + h. Since the true root is r, and h = r x0, the number h measures how far the estimate x0 is from the truth.

Since h is ‘small,’ we can use the linear (tangent line) approximation to conclude that

0 = f(r) = f(x0 + h) f(x0) + hf ' (x0),

and therefore, unless f ' (x0) is close to 0,

h f(x0)/ f ' (x0) .

It follows that

r = x0 + h x0 f(x0)/ f ' (x0) .

Our new improved (?) estimate x1 of r is therefore given by

x1 = x0 f(x0)/ f ' (x0) .

The next estimate x2 is obtained from x1 in exactly the same way as x1 was obtained from

x0: x2 = x1 f(x1)/ f ' (x1) .

Continue in this way. If xn is the current estimate, then the next estimate xn+1 is given by

xn+1 = xn f(xn)/ f '(xn)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote