Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Created October 2, 2020 09:33
Show Gist options
  • Save sverhoeven/6d41c2342bbf4de7537be4926f36c769 to your computer and use it in GitHub Desktop.
Save sverhoeven/6d41c2342bbf4de7537be4926f36c769 to your computer and use it in GitHub Desktop.
run-cpp-on-web: vega
#include <iostream>
#include <iomanip>
#include "newtonraphson.hpp"
int main() {
float initial_guess = -4;
float tolerance = 0.001;
NewtonRaphson newtonraphson(tolerance);
newtonraphson.solve(initial_guess);
std::cout << std::fixed;
std::cout << std::setprecision(2);
for (Iteration iteration : newtonraphson.iterations) {
std::cout << "index = " << iteration.index;
std::cout << " x = " << iteration.x;
std::cout << " y = " << iteration.y;
std::cout << " slope = " << iteration.slope;
std::cout << " delta_x = " << iteration.delta_x << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment