Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I must write a program that uses Runge-Kutta method to integrate the following f

ID: 3640392 • Letter: I

Question

I must write a program that uses Runge-Kutta method to integrate the following functions:

1. 5 - 1/x + 3 * x * x, from 0.001 to 20
2. sin(3*x) from 0 to pi
3. 2*x*arctan(x) from -2 to 2
4. Math.pow(x,5) * Math.pow(e,Math.pow(x,3)) from 0 to 1

I know the code for Runge-Kutta follows:

public double rk(double x, double y, double step) {
double h = step
double k0 = h * f(x,y);
double k1 = h * f(x + .5 * h, y + .5 * k0);
double k2 = h * f(x + .5 * h, y + .5 * k1);
double k3 = h * f(x + h, y +k2);

return y + 1.0/6.0 * (k0 + 2 * k1 + 2 * k2 +k3);

I know i must use a loop from the beginning of the integral to the end but my code is still off. I'm asking for the code.

Thanks

Explanation / Answer

public class RungeKutta { // The number of steps to use in the interval public static final int STEPS = 100; // The derivative dy/dx at a given value of x and y. public static double deriv(double x, double y) { return ( 5 - 1/x + 3 * x * x); return(sin(3*x); return (2*x*arctan(x)); return(Math.pow(x,5)); return x * Math.sqrt(1 + y*y); } // The `main' method does the actual computations public static void main(String[] argv) { // `h' is the size of each step. double h = 1.0 / STEPS; double k1, k2, k3, k4; double x, y; int i; // Computation by Euclid's method // Initialize y y = 0; for (i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote