Skip to content

Added Newton Raphson Method using C++ #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions cpp/NonLinear_Methods/newton_raphson.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

// C++ program for implementation of Newton Raphson Method
#include<bits/stdc++.h>
#define ERROR 0.001
using namespace std;

double func(double x)
{
return x*x*x - x*x + 2; //Define a Function
}

double derivative(double x)
{
return 3*x*x - 2*x; //Define its derivative
}

// Function to find the root
void NRaphson(double x)
{
double h = func(x) / derivative(x);
while (abs(h) >= ERROR)
{
h = func(x)/derivative(x);
x = x - h;
}

cout << "One of the roots is : " << x;
}

int main()
{
double x_0 = -10; // Initial Guess
NRaphson(x_0);
return 0;
}