I have to create a java program that integrates equations into the 4th order Run
ID: 3640280 • Letter: I
Question
I have to create a java program that integrates equations into the 4th order Runge-Kutta Method but I have absolutely no idea how to incorporate the equations.
The code for the Runge-Kutta method is the following.
/* call this function in a loop from starting point to stopping point */
public double rk(double x, double y, double step){
double h = step;
double k0 = h * f(x, y);
double k1 = h * f(x + 0.5 * h, y + 0.5 * k0);
double k2 = h * f(x + 0.5 * h, y + 0.5 * k1);
double k3 = h * f(x + h, y + k2);
return y + 1.0/6.0 * (k0 + 2 * k1 + 2 * k2 + k3);
For example, if my equation was 5 - 1/x + 4 * x * x from 0.001 to 20, how would I integrate this?
Explanation / Answer
public static void step (double t, double dt,double [] var,double [] vel, Derivable func ) { double k1_var, k1_vel; double k2_var, k2_vel; double k3_var, k3_vel; double k4_var, k4_vel; for (int i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.