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

The program should be in either C, C++, python or Java. Consider the differentia

ID: 3818712 • Letter: T

Question

The program should be in either C, C++, python or Java.

Consider the differential equation x' = (tx - x^2)/t^2 with x(1) = 2 (exactly), for t belongs to [1, 3]. For each program below, show (either as comments, or outside of the program) how you calculated the particular the formulas used in the program. Use the Euler method (described in Sect. 5.2 of [Burden & Faires]) with h = 2^-7. Show your program, and print x(t) for t = 3/2, 2, 5/2, 3. Use the Taylor method of order 2 (described in Sect. 5.3) with h = 2^-6. Show your program, and print x(t) for t = 3/2, 2, 5/2, 3. Use the Runge-Kutta method of order 4 (described in Sect. 5.4) with h = 2^-5. Show your program, and print x(t) for t = 3/2, 2, 5/2, 3. Use the Runge-Kutta method of order 4 with h = 2^-6, and print x(t) for t = 3/2, 2, 5/2, 3. The Runge-Kutta method of order 4 has a truncation error of the form |E(h)| lessthanorequalto C middot h^4, when h is small enough. To estimate the constant C the following error-testing experiments are carried out with different values of h. We let h = 2^-k for k = 2, 3, 4, ellipsis, until we get a result for x(3) that does not vary in the 4 most significant decimals anymore (i.e., as h becomes smaller and smaller, the 4 most significant decimals remain stable). At this point we presume that E(h) is the error that corresponds to the round-off attached to the 4th significant digit; i.e., |E(h)| approximately 1/2 10^-4. Show your program (which makes calls to the Runge-Kutta routine of question 3 in a for-loop). Print your estimate of C, the last value or k and h, as well as the last 5 values of x(3) in the experiment.

Explanation / Answer

public class Euler {
private static void euler (double y0, int a, int b, double h) {
int t = a;
double y = y0;
while (t < b) {
System.out.println ("" + t + " " + y);
t += h;
y += h * compute (t, y);
}
System.out.println ("DONE");
}

public static void main (String[] args) {
int[] steps = {2, 5, 10};
for (int stepSize : steps) {
System.out.println ("Step size: " + stepSize);
euler (2, 1,3,2.0*(10^-7));
}
}
  
public static double compute (int t, double x) {
   return (t*x-(x*x))/(t*t);
   }
}