Last active
October 7, 2020 11:57
-
-
Save sverhoeven/b34819cb297fac2e84a3a53bf18c73d0 to your computer and use it in GitHub Desktop.
run-cpp-on-web: webassembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "newtonraphson.hpp" | |
#include "problem.hpp" | |
#include <cmath> | |
// Define the constructor method of NewtonRaphson instances | |
NewtonRaphson::NewtonRaphson(float tolerance_in) : tolerance(tolerance_in) {} | |
// Define the 'solve' method of NewtonRaphson instances | |
float NewtonRaphson::solve(float initial_guess) { | |
float x = initial_guess; | |
float delta_x = 0; | |
do { | |
delta_x = equation(x) / derivative(x); | |
x = x - delta_x; | |
} while (std::abs(delta_x) >= tolerance); | |
return x; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment