Greetings,
I am trying to implement a 4th order Runge Kutta for the following equations on the interval 1 less than or equal to t less than or equal to 2, with h = 0.01: x' = x^-2 + log y + t^2 y' = e^y-cos(x) + (sin t)x - 1/x^3y^3
with x(2)=-2 and y(2) = 1.
Now, I started to implement it in code is a basic form:
function rungekuttah = 0.01;t = 1;w = 1; fprintf('Step 0: t = %12.8f, w = %12.8f\n', t, w);for i = 1:100 k1 = h*f(t,w); k2 = h*f(t+h/2, w+k1/2); k3 = h*f(t+h/2, w+k2/2); k4 = h*f(t+h, w+k3); w = w + (k1+2*k2+2*k3+k4)/6; t = t+h; fprintf('Step %d: t = %6.4f, w = %18.15f\n', i, t, w);end
but the tricky part is that I'm dealing with x,y, and t in both equations, but in searches and books I see, all I see is a function dependent on x (or y) and t with an initial condition, not all three at once.
Any hints or suggestions? I'm a bit stuck in neutral.
Thanks!
Best Answer