Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- NewtonsMethod();
- }
- private static void NewtonsMethod() {
- double g = 2.0;
- double tol = Math.pow(10F, -12);
- double old = g+1F;
- int counter = 0;
- while(Math.abs(g-old) > tol) {
- old = g;
- g = old - (f(old)/df(old));
- counter++;
- System.out.println("Iteration " + counter + ": " + g);
- }
- }
- private static double f(double x) {
- return Math.pow(Math.E, x)-3F*x-1;
- }
- private static double df(double x) {
- return Math.pow(Math.E, x)-3F;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement