How do I read this code?
Mostra commenti meno recenti
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 Commento
Douglas Alves
il 12 Mag 2014
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!