Hi, I'm trying to solve the equation: y'' + k(t)y = 0 where k(t) is an array of values and y(0) = 1/2 and y'(0) = 1 in the range t = 0 to 20.
I understand it is possible to solve this as 2 coupled first order differential equations using ode45 as follows when k is constant:
k = 2
syms y(t)
[System] = odeToVectorField(diff(y, 2) == -(k).*y);
M = matlabFunction(System,'vars', {'t','Y'});
sol = ode45(M,[0 20],[1/2 1]);
fplot(@(x)deval(sol,x,1), [0, 20])
Please will you help me introduce the dependance on t of k(t), thanks!
Best Answer