ODE45 how do I interpret this code...
古いコメントを表示
if true
% code
end
function elements
tspan = [0 1];
inits = [0 1];
[t,y] = ode45(@Y,tspan,inits);
plot(t,y)
function deriv = Y(t,y)
deriv = zeros(size(y));
deriv(1) = y(2) ;
deriv(2) = -y(1);
% the same as deriv = [y(2); -y(1)]
The first part I understand y is created and initiate with a vector [ 0 1 ] which is the initial condition. However the part deriv(1) = y(2) and the following line confuses me. I think that since y was created when matlab goes to the function deriv it will see the function as deriv(1) = 1 and deriv(2) = -0 since y exists... However the code works and matlab sees the function ( I mean the Y's ) as variables y1 and y2 ... Could anyone clarify this to me please. How does MATLAB read this... Sorry that's my second question about it. I don't think I got it.. I've already read doc ode45 and doc function it's not clear in there.
採用された回答
その他の回答 (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!