
Mini project assignmentnewton raphson method
code:
#include<iostream>
#include<cmath>
#include<cassert>
//this program is on newton raphson method//
int main(int argc, char *argv[])
{
float dx,y,y1, fx,fx1,fdiff,fdiff1;
for(float i=1.00;i<101.00;i++)
{
fx=exp(i)+(i*i*i)5;fx1=exp(i1)+((i1)*(i1)*(i1)5);
fdiff=exp(i)+(3*i*i);fdiff1=exp(i1)+(3*(i1)*(i1));
y=i(fx/fdiff);y1=(i1)(fx1/fdiff1);
dx=abs(y1y);
std::cout<<“y at “<<i1<<” is “<<y1<<” y at “<< i<<” is “<<y<<std::endl;
if(dx< 1*exp(5))
{
std::cout<<“Final iterated value is at “<<i<<” th iteration .i.e “<<y<<std::endl; break;
}
}
return 0;
}
Result:
l@DESKTOP53SFBVP:~/workspace$ g++ nr.cpp
l@DESKTOP53SFBVP:~/workspace$ ./a.out
y at 0 is 4 y at 1 is 1.22414
y at 1 is 1.22414 y at 2 is 1.46418
Final iterated value is at 2 th iteration .i.e 1.46418
Issue: code is ending before it reaches the tolerance 10^(5)
what’s the issue in this code! thanks in advancee
Log in to reply.