필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by