I used the ODE to vector field function to change my 2 coupled 2nd order ODEs to a system of 1st order ODEs.
syms k1 k2 m t x1(t) x2(t) YDx1 = diff(x1);D2x1 = diff(x1,2);Dx2 = diff(x2);D2x2 = diff(x2,2);Eq1 = D2x1 == (-(k1+k2)*x1+(k2)*x2)/mEq2 = D2x2 == ((k2*x1)+((k1+k2)*x2))/m[V,Subs] = odeToVectorField(Eq1, Eq2)ftotal = matlabFunction(V, 'Vars',{t,Y,k1,k2,m})
It generated this
ftotal = function_handle with value: @(t,Y,k1,k2,m)[Y(2);((k1+k2).*Y(1)+k2.*Y(3))./m;Y(4);-((k1+k2).*Y(3)-k2.*Y(1))./m]
However, when I tried to use ODE45 to solve it, i got errors. The initial conditions are x(0)= (1 0)' and αΊ‹(0)= (0 0)'
tspan = [0 20];y0 = [1 0; 0 0];[T,Y] = ode45(ftotal,tspan,y0)plot(T,Y)grid
Any help would be appreciated.
Thank you
Best Answer