I am trying to solve the second order ODE x''=[ 9/4-(12/(5-3exp(2t)))exp(2t)] x(t), with ICs x'=x=0 at t=-1 for -1<=t<=0, using Runge-Kutta 4. Here is my MWE:
a = -1; b = 0; N = 1000;
t = zeros(1, N);
w1 = zeros(1, N);
w2 = zeros(1, N);
w1(1) = 0; w2(1) = 0;
h = (b – a)/N;
t(1) = a;
F1 = @(t, x1, x2) x2;
F2 = @(t, x1, x2) ((12*exp(2*t))/(3*exp(2*t) – 5) + 9/4)*x1;
for i = 1:(N-1)
K11 = h*(F1(t(i), w1(i), w2(i)));
K21 = h*(F2(t(i), w1(i), w2(i)));
K12 = h*(F1(t(i) + 0.5*h, w1(i) + 0.5*K11, w2(i)+ 0.5*K21));
K22 = h*(F2(t(i) + 0.5*h, w1(i) + 0.5*K11, w2(i)+ 0.5*K21));
K13 = h*(F1(t(i) + 0.5*h, w1(i) + 0.5*K12, w2(i)+ 0.5*K22));
K23 = h*(F2(t(i) + 0.5*h, w1(i) + 0.5*K12, w2(i)+ 0.5*K22));
K14 = h*(F1(t(i) + h, w1(i) + K13, w2(i)+ K23));
K24 = h*(F2(t(i) + h, w1(i) + K13, w2(i)+ K23));
w1(i+1) = w1(i) + (K11 + 2*K12 + 2*K13 + K14)/6;
w2(i+1) = w2(i) + (K21 + 2*K22 + 2*K23 + K24)/6;
t(i+1) = a + i*h;
end
My issue is that the trivial solution x=0 is returned. I have tried the code with various other second order ODEs that I know the solution for and I get the expected results. If I make the ICs tiny instead of zero (say 0.000001) it seems to force a correct-ish looking, but obviously incorrect, solution. Any help is appreciated. I am new to Matlab. I get the same thing using ode45. Perhaps there is no non-trivial solution but there should be.
Best Answer