# How can I get ode solutions for the time steps I run the model instead of having values at the calculation time steps the solver chooses?

조회 수: 12 (최근 30일)
Betty Fritz 2011년 6월 22일
Hi,
I work with ordinary differential equations, which describe an aquatic food web. So I calculate biomasses. I have in my function file 3 ode’s and use ode45 to solve them. In my third ode I use the mean of the last 30 values of the values calculated in the first and second ode.
I run my model for 3000 time steps, which I defined as 1:1:3000. But the solver does not calculate the solutions of the ode’s in the same time steps. The solver uses small time steps, when the fluctuations of the calculated values are high and bigger steps, when the fluctuations are lower. So when my system is stable, it may happen, that the solver does not calculate values for each of my predefined time step.
The problem is now that I want to use for the calculations of the means (last 30 values of ode 1&2) not the last 30 values which were calculated by the solver, but the solutions of the ode’s of the 30 time steps I defined.
So my idea was to tell the solver to use for the calculations the time steps I defined. Does anybody know how to do this? Or do you maybe have another solutions for my problem?
I hope I explained my problem clearly, if there are any questions – please ask.
It would be great if anybody could help me!
Thanks, Betty

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

### 답변 (2개)

Arnaud Miege 2011년 6월 22일
Have a look at the documentation for ode45:
tspan: A vector specifying the interval of integration, [t0,tf]. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). To obtain solutions at specific times (all increasing or all decreasing), use tspan = [t0,t1,...,tf].
For tspan vectors with two elements [t0 tf], the solver returns the solution evaluated at every integration step. For tspan vectors with more than two elements, the solver returns solutions evaluated at the given time points. The time values must be in order, either increasing or decreasing.
HTH,
Arnaud
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

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

Betty Fritz 2011년 6월 23일
Thanks for your answer. But this is not the solution for my problem. The problem I have is described in the paragraph below (copied from the documentation for ode45).
Specifying tspan with more than two elements does not affect the internal time steps that the solver uses to traverse the interval from tspan(1) to tspan(end). All solvers in the ODE suite obtain output values by means of continuous extensions of the basic formulas. Although a solver does not necessarily step precisely to a time point specified in tspan, the solutions produced at the specified time points are of the same order of accuracy as the solutions computed at the internal time points.
I want the solver to use specified internal time steps, because I need the means of the last 30 values within the solving process.
Do you know what I mean?
Thanks, Betty
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Arnaud Miege 2011년 6월 28일
I don't think you can access the internal time steps of the solver. You can control the step size with odeset though:
http://www.mathworks.com/help/releases/R2011a/techdoc/ref/odeset.html

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

### 카테고리

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