Solving diffeerntial equations numerically

I need to solve a set of ODEs from [Ts, Tend]. I want the solution to be output every dT. Within that interval dT, a vaiable step method should be used, but I need the solution every dT. I can use the codes in Matlab but this output every dT (without interpolation) is what I need.
Atique Malik

댓글 수: 3

Thanks!
Shahid Malik
Shahid Malik 대략 1시간 전
이동: Walter Roberson 29분 전
I need this as I am simulating a controller system where the controller algorithm runs every dT. So I need the solution every dT as it happens, not after the fact.
It sounds as if you need a fixed-step ode instead of a variable-step ode.
You can reduce the effect of interpolation by setting MaxStep in odeset() to some fraction of dT, at the expense of slowing down the solver.

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

답변 (4개)

Steven Lord
Steven Lord 29분 전

0 개 추천

If you use the ode object you can call its solve method to return the solution at specified times.
If you're using a specific ODE solver like ode45 you can specify tspan as a vector with more than 2 values to return the solution at those specified times. Alternately you can call ode45 with one output argument sol then call the deval function with sol and the specified times as input to evaluate that solution at the specified times.
Or do you want to prevent the solver from taking steps that would take it outside the interval it's in, for example you want to solve at times t = 0, t = 1, t = 2, ... and you don't want the solver to be able to step from t = 0.5 to t = 1.5 without also stepping at t = 1? If so call the solver multiple times, solving the ODE on one interval then using the solution at that endpoint as the initial condition for solving on the next interval.
Walter Roberson
Walter Roberson 대략 3시간 전

0 개 추천

It is not currently possible to solve odes numerically with variable step size, but at the same time get the output at fixed intervals without any interpolation .
If you use ode objects then the solve() method interpolates solutions.
If you use solvers such as ode45() passing in a vector of times, then when it detects that it has crossed one of the times, it does interpolation to output the result at that time.
Torsten
Torsten 대략 3시간 전
편집: Torsten 대략 2시간 전
If you want solutions at multiples of dt without interpolation, the only way I can think of is to call the ode integrator in a loop with the multiples of dt as end times of integration. But even here, I'm not sure if the integrator does not internally integrate past "tend" and interpolates the solution to "tend". Why do you think it's necessary for your application to run without interpolation of the solution at the output times ?
dt = 0.1;
nsteps = 10;
tstart = 0;
tend = dt;
y0 = 1;
fun = @(t,y) y;
sol_t = zeros(nsteps+1,1);
sol_y = zeros(nsteps+1,1);
sol_t(1) = tstart;
sol_y(1) = y0;
for i = 1:nsteps
tspan = [tstart tend];
[T,Y] = ode45(fun,tspan,y0);
tstart = tend;
tend = tend + dt;
y0 = Y(end,1);
sol_t(i+1) = T(end);
sol_y(i+1) = Y(end,1);
end
plot(sol_t,sol_y)
Shahid Malik
Shahid Malik 대략 1시간 전

0 개 추천

I need this as I am simulating a controller system where the controller algorithm runs every dT. So I need the solution every dT as it happens, not after the fact.

카테고리

태그

질문:

대략 13시간 전

댓글:

대략 3시간 전

Community Treasure Hunt

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

Start Hunting!

Translated by