how I can fix sample time in ode45
Show older comments
I want to fix the sample time (for example, T=0.5) in ode45. How can I do it? If it is not possible, do we have another way to fix the sample time in Matlab?
tspan = 0:1:10000;
y0 = [0.2,0.3];
[t,y] = ode45(@(t,y) odefcn(t,y), tspan, y0);
%
function dx = odefcn(t,x)
dx = zeros(2,1);
u=[2 -2]*x(1:2)+1;
dx(1)=x(1)-2*x(2)
dx(2)=-x(2)+u
end
Accepted Answer
More Answers (1)
Walter Roberson
on 29 Oct 2023
0 votes
You cannot do that. ode45() is always a variable-step solver. So is ode15s, ode23s, ode78, ode113, ode89.
If you need a fixed step solver then see https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b#answer_107643
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

