Is it possible to extract the time and two output variables from ODE45?

조회 수: 36 (최근 30일)
Tyler Bikaun
Tyler Bikaun 2017년 1월 17일
댓글: Jan 2017년 1월 20일
Hello,
I have written a function which holds state space equations for ODE45 to solve, being in the nature of:
function zdot = odess(t,z)
In my mainscript which calls upon this function and has the initial conditions for the ode, I am recalling the outputs by:
[t,z] = ode45(@odess, t_step, z0, opts);
However, is it possible to get a second variable from the 2nd code listed above? For example:
[t,z,new_output] = ode45(@odess, t_step, z0, opts);
Thanks for your time.
  댓글 수: 2
Jan
Jan 2017년 1월 17일
Where does the "new_output" come from? What do you expect in this variable?
Tyler Bikaun
Tyler Bikaun 2017년 1월 19일
Sorry Jan, the syntax in the 3rd code above is just off of my head and not what I actually expect to be able to do. I want to be able to extract z(1) from my odescript (see comments below), I thought that that may be a way to achieve it.

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

답변 (2개)

Torsten
Torsten 2017년 1월 17일
The easiest way is to reculculate new_output from t and z after the call
[t,z] = ode45(@odess, t_step, z0, opts);
Best wishes
Torsten.
  댓글 수: 8
Torsten
Torsten 2017년 1월 20일
If you set up your code as above, the variable z(9) is z(1), integrated over time, i.e.
z_9(t)=integral_{0}^{t} z_1(t) dt.
If you want to output z(1), just use your previous code without any changes and use the command
plot (t,z(:,1));
after the call to ode45, as I already suggested.
Your assertion
z(1) isn't included in the output matrix "z" from [t,z] = ode45(@odess,t_step,z0, opts), i think what is included are only zdots.
is simply wrong.
Best wishes
Torsten.
Jan
Jan 2017년 1월 20일
@Tyler: An integrator as ODE45 gets the start position (or "state vector") as input, than calls the function to be integrated, which replies the derivatives and accumulates them. For each successful time step, the new position is replied. Therefore the output of the integrator contains the positions (state varaibales) and the first element is its first component.
You can simply check this manually: Computer your odess(t,z) for the inital time and start vector and check the first row of the output of the integrator.

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


Walter Roberson
Walter Roberson 2017년 1월 17일
편집: Walter Roberson 2017년 1월 17일

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by