Suppose I run this code by typing in the command line [t p] = ode45(@spring,[0 4], [0 0]); I don't understand first of all how MATLAB knows p is a vector and how does MATLAB know p is a 2×1 matrix … ( It has to be a 2×1 matrix because I have 2 expressions in order to solve the system of differential equations). I think the answer comes from the initial values [0 0] but the initial value is not p!! p is unknown how come pdot is created…?
function pdot = spring(t,p,c,w) pdot = zeros(size(p));pdot(1) = p(2); pdot(2) = sin(t) -c*p(2) - (w^2)*p(1);
Best Answer