Rohan G Euler's method but in function form
I am bored I will make a math function
import java.util.*;
import java.math.*;
public class Euler {
public int diffy;
public int diffx;
public double initialx;
public double initialy;
public double finalx;
public int increment;
public double derivative;
public double deltax;
public double deltay;
public static void wholethingig() {
Scanner in = new Scanner(System.in); // Create a Scanner object
System.out.println("what is the coefficient of y in dy/dx = x + y");
int diffy = in.nextInt(); // Read user input
System.out.println("what is coefficient of x in dy/dx = x + y");
int diffx = in.nextInt(); // Read user input
System.out.println("what is the starting x coordinate");
double initialx = in.nextDouble(); // Read user input
System.out.println("what is the starting y coordinate");
double initialy = in.nextDouble(); // Read user input
System.out.println("what is the final x coordinate");
double finalx = in.nextDouble(); // Read user input
System.out.println("how many increments");
int increment = in.nextInt();
System.out.println("Equation is: dy/dx = " + diffx + "x" + " + " + diffy + "y");
System.out.println("Starting coordinate = " + "(" + initialx + ", " + initialy + ")");
System.out.println(increment + " increments to get to f(" + finalx + ")");
double deltax = (finalx - initialx)/increment;
System.out.println(deltax);
for (int i = 0; i < increment; i++ ) {
double derivative = (initialx * diffx) + (initialy * diffy);
double deltay = derivative * deltax;
System.out.println("(x,y) = " + "(" + initialx + ", " + initialy + ") | " + "Delta x = " + deltax + " | " + "dy/dx = " + derivative + " | " + "deltax * (dy/dx) = " + deltay + " | " + "delta x(dy/dx) = " + deltay + " | " + "((x + dx), (y + dy))" + " = (" + initialx + ", " + initialy + ")");
// System.out.println("Delta x = " + deltax + ".");
// System.out.println("dy/dx = " + derivative + ".");
// System.out.println("delta x(dy/dx) = " + deltay + ".");
// System.out.println("((x + dx), (y + dy))" + " = (" + initialx + ", " + initialy + ")");
// System.out.println(deltax);
initialy = initialy + deltay;
initialx = initialx + deltax;
// System.out.println("diffx = " + diffx);
// System.out.println("diffy = " + diffy);
// System.out.println("derivative = " + derivative);
// System.out.println("finalx = " + initialx);
}
System.out.println("Final approximation using Euler's method: (" + initialx + ", " + initialy + ")");
}
public static void main(String[] args) {
wholethingig();
// getDeltaX();
}
}
Euler.main(null);