Effacer les filtres
Effacer les filtres

Convert function handle to a function in ODE45

1 vue (au cours des 30 derniers jours)
Sattik Basu
Sattik Basu le 2 Déc 2022
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?

Réponses (1)

Walter Roberson
Walter Roberson le 3 Déc 2022
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)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by