I am trying to model the equation y" + 4y = 0, with initial conditions y(0) = 1 and y'(0) = 0, in Matlab. The snippet of code below shows a working approximation of the position as a function of time for the above ODE:
clear
syms y(t)
%Differential Equation Conversion
P = odeToVectorField(diff(y, 2) == -4*y);
M = matlabFunction(P,'vars',{'t','Y'});
%Position Approximation
pos_solution = ode45(M,[0 20],[1 0]);
x = linspace(0,20,1000);
y = deval(pos_solution,x,1);
%Plot of Position as a function of time
figure(3)
plot(x,y,'b');
I am trying to take this data produced and find the velocity of the system as a function of time, but have no idea how to do so. Any help with this would be appreciated.
yrepresents. - TroyHaskiny = deval(pos_solution,x,1);returns the integral of y', i.e., y (or position ifyrepresents that). If you want y' (velocity if y represents position, the integral of y''), then usey = deval(pos_solution,x,2);as per the documentation. Or just usey = deval(pos_solution,x);to return both together. - horchlerdeval(XINT,SOL,IDX). That clears it up for me! Much appreciated. - Alex Walker