/* Approximate a solution to the initial value problem u' = f(t,u) with u(t0) = u0 on the interval [t0,tN] using N time steps of the RK4 method. */ #include #include #define N 1024 static double t0=0,u0=1,tN=10,h; double f(double t,double u){ return exp(-u)*sin(t+u); } double rk4(double t,double u){ double k1=h*f(t,u); double k2=h*f(t+h/2,u+k1/2); double k3=h*f(t+h/2,u+k2/2); double k4=h*f(t+h,u+k3); return u+(k1+2*(k2+k3)+k4)/6; } int main(){ printf("This is problem 1 on exam part 2.\n"); h=(tN-t0)/N; double u=u0; for(int n=0;n