How do I read this code?
古いコメントを表示
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);
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!