MATLAB: Duffing equation ODE45

ode45

I solved the duffing equation using ODE45. Below is the code.
It works fine and plots as expected. However, I noticed that the difference of 't' is not same. How can I have the 't' value equally spaced?
—————————————————–
tspan = [0 100];
x0=[1,0];
[t,y]=ode45(@duff1,tspan,x0)
figure(1)
%first value
% subplot(221)
plot(t,y(:,1)); %plot(t,y);
xlabel('Time');
ylabel('State');
title('k3=0,k=1,x0=1');
function result = duff1(t,y)
c = 0.1;
k3=0;
k=1;
result= [y(2); -c*y(2)-k*y(1)-k3*y(1).^3]
end

Best Answer

Use:
tspan = linspace(0, 100, 50);
to create a ‘tspan’ vector with 50 elements between 0 and 100.
Related Question