Newton Raphson Method C++ Program

#include<iostream>
#include<cmath>
using namespace std;
double newt(double, double);

int main(){
	double guess1=10, guess2=-10, accuracy=0.1;
	double result1=newt(guess1,accuracy);
	double result2=newt(guess2,accuracy);
		
	cout<<"The roots are"<<'\t'<<result1<<","<<'\t'<<result2<<endl;
	return 0;
}
	
double newt(double xn, double accu){
	double temp;
	double f=(6*xn*xn)-(17*xn)-14;
	double fdash=(12*xn)-17;
	double xnplus1=xn-(f/fdash);
	temp=xn;
	xn=xnplus1;
	
	if(abs(temp-xn)>=accu){
		return newt(xn, accu);
		
	}
	return xn;
		
}

[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.