Convert function handle to a function in ODE45
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have a symbolic matrix J
J = [2*y(1), 4*y(2), y(1)*y(2);
y(3), 2*y(1)^2, 5*y(2);
5*y(3), 2*y(2)*y(1), 2*y(2)];
I can convert it to a function handle using
Jnew = matlabFunction(J)
So now it shows as Jnew = @(y(1),y(2),...)reshape([.....],[3,3]
The issue begins now. Since I want this J to be used in an ode45 environment. For example
[T,Y] = ode45(@(t,y) myode(t,y,Jnew), span, IC)
where myode is
function dy = myode(t,y,J)
vars = y(1:3)
A = [1 2 3;
1 3 4;
7 6 5];
dy = A*vars + J*vars;
end
How can I use J as an input here?
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 12 月 3 日
Do not do that. Instead use
A = [1 2 3;
1 3 4;
7 6 5];
Jnew = matlabFunction(A*y(:) + J*y(:), 'vars', {y(:)});
[T,Y] = ode45(Jnew, span, IC)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!