Output additional vectors from ode45

조회 수: 66 (최근 30일)
Auwais Ahmed
Auwais Ahmed 2021년 11월 27일
댓글: Star Strider 2021년 11월 28일
I am calculating concentrations and radii at all the timesteps within the ode45 loop. What is the best way to output all that information?
  댓글 수: 1
Jan
Jan 2021년 11월 28일
As diagrams? In 2 or 3 D? As text files? As binary files?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 11월 28일
Adding additional outputs is permitted, providing that they are not used in the ode45 call. Normally, this is not a problem, because unless more outputs are requested in the calling script or function, only the first output is used.
The only way to recover them is to use the returned independent variable (usually time) vector and the solved dependent variables in a for loop and save the other desired output at each step of the loop.
tspan = [0 10];
ic = [0.1; -0.1];
[t,y] = ode45(@odefcn, tspan, ic);
for k = 1:numel(t)
[~,radii(k,:)] = odefcn(t(k),y(k,:));
end
figure
yyaxis left
plot(t,y)
ylabel('y(t)')
yyaxis right
plot(t, radii)
ylabel('Radius')
grid
function [dy,radius] = odefcn(t,y)
dy = zeros(2,1);
radius = hypot(y(1),y(2));
dy(1) = y(1);
dy(2) = radius * cos(y(1)) * sin(y(2));
end
.
  댓글 수: 2
Auwais Ahmed
Auwais Ahmed 2021년 11월 28일
thanks
Star Strider
Star Strider 2021년 11월 28일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Auwais Ahmed
Auwais Ahmed 2021년 11월 28일
I am caluculating a value for a parameter eg radius at each time step in ode45. At the end I want to output all radius at all time t
  댓글 수: 1
Auwais Ahmed
Auwais Ahmed 2021년 11월 28일
In other words I just want to add an additional output argument in addition to the default y and t

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by