필터 지우기
필터 지우기

Getting data from inside ode15s solver

조회 수: 16 (최근 30일)
Brandon
Brandon 2020년 1월 30일
댓글: Star Strider 2020년 1월 31일
I am using ode15s to solve a differential equation in a combustion particle system. The problem that I have is that the ode_func that I am putting in ode15s has some data inside of it that I want to get outsie of the function. This data is not the output of the ode_func, so it's not saved as output. My question is how is the best way to get it out? Should I use a global variable inside the ode_func that updates it's value while it solves, then I can access it outside of the func? Or is it possible to add another output to the ode_func? I'm not sure how the ode15s would handle multiple outputs from the ode_func.

채택된 답변

Star Strider
Star Strider 2020년 1월 30일
Do not use global variables!
Write one version of your ODE function that ode45 (or whatever solver you are using) then solves.
Then in a for loop, use those independent and dependent variable arrays with a second version of your ODE function that uses the solved values for the independent and dependent varialbles and instead returns the varialbles you are interested in in each iteration of the loop.
That has worked for me in the past, and it is likely more efficient than any other option.
  댓글 수: 4
Brandon
Brandon 2020년 1월 31일
Ok. Last question: what was the point of the doing your suggestion in a for-loop? Are you saying that I should iterate over the timesteps that the ode solver output, then use the output variable as an input to my altered odefunc to calculate the things I want?
Star Strider
Star Strider 2020년 1월 31일
The for loop is essentially the only way to get the step-by-step data for the other variables, because of the way ODE functions are written. (They are intended to be evaluated step-wise.) At each iteration of the for loop, calculate the desired variables with the specific values of the integrated independent and dependent variables and return the other variables as an output of the slightly revised ODE function.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by