Solve x sin x ex x sin x2 0 by the Newtonraphosn method w

Solve x sin x - e^x + x sin (x^2) = 0, by the Newton-raphosn method with initial value of x = -2.

Solution

#include<stdio.h>
#include<math.h>

void main(){
  
float x1, f0, fd0, e;
float x0=-2; //initial value
printf(\"\ \ Given equation: xsinx -e^x +x sin(x^2)\");
//xn+1 = xn - f(xn) / f \'(xn)
//f(x)=xsinx -e^x +x sin(x^2)
float f(float x)
{
   return x*sin(x) -exp(x) +x*sin(x*x);
}
//f\'(x)= sin x + x cos x - e^x +sin(x^2)+2x^2 cos(x^2)
float fd(float x)
{
   return sin(x)+x*cos(x) -exp(x) +sin(x*x) + 2*(x*x)*cos(x*x);
}
printf(\"\ f(x0)\\t\\tf(x0)\\t\\tx1\\t\\tError\");
printf(\"\ -----------------------------------------------------\");

do
{
f0 = f(x0);
fd0 = fd(x0);
x1 = x0 - (f0/fd0);
e =fabs((x1-x0)/x1);

if( e < 0.0001){
printf(\"\ \ Approximate Root = %.5f\", x1);
break;
}
else{
printf(\"\ %.2f\\t\\t%.3f\\t\\t%.3f\\t\\t%.4f\",f(x0),fd(x0),x1,e);
x0 = x1;
}
}
while(e>=0.0001);

}

 Solve x sin x - e^x + x sin (x^2) = 0, by the Newton-raphosn method with initial value of x = -2.Solution#include<stdio.h> #include<math.h> void ma

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site