Convert function handle to a function in ODE45

1 回表示 (過去 30 日間)
Sattik Basu
Sattik Basu 2022 年 12 月 2 日
回答済み: Walter Roberson 2022 年 12 月 3 日
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?

回答 (1 件)

Walter Roberson
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)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by