How do I read this code?
Show older comments
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 2x1 matrix ... ( It has to be a 2x1 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);
1 Comment
Douglas Alves
on 12 May 2014
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!