The last entry in tspan must be different from the first entry. ODE45
27 次查看(过去 30 天)
显示 更早的评论
Hello,
I am using ODE45 to solve a ODE, where the time steps are very small. while sloving it shows error the last entry in tspan must be different from the first entry. I went back a chek, but my intial and final times are not same. Can someone provide me an alternative way ?
tInitial =0.48965737046814611799910865741481
tFinal =0.48965737046814611799928732454269
tspan = [tInitial tFinal]
[t,N] = ode45(@(t,N) thisObj.diffusionalGrowth(), tspan, oldDia);
0 个评论
采纳的回答
Bjorn Gustavsson
2019-6-11
tInitial and tFinal differ in the ~22nd decimal. That is not much for a double-precision representation. Why not run the simulation from 0 to 1.78e-22? And are that the entire time-scale you want to integrate the DE? If that time is in units of seconds it is a very short time, if it is in hours it is still a very short time, even if it is in units of years it is still about a 5 femtoseconds...
HTH
3 个评论
Bjorn Gustavsson
2019-6-11
That your system is dynamic is not making it impossible to integrate the system for longer periods of time. You can do things like this:
function dN = your_ode(t,N,additional,arguments)
Dynamic_variations = other_function(t,y,arguments);
dN_additional = additional(1)*cos(additional(2)*t);
dN = N + Dynamic_variations + dN_additional;
end
Then integrate from your start-time for the entire duration:
additional = [2,4*pi];
arguments = {123,'s'};
t_span = [0 exp(pi)];
N0 = 1;
[t,N] = ode45(@(t,N) your_ode(t,N,additional,arguments), t_span, N0);
If you have discrete events it might be possible to use the events-handling capacity - see ballode.m for an example of how to handle this.
HTH
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!