How can I solve the periodic function with ode45 solver?

1 Ansicht (letzte 30 Tage)
Doruk Can Ogan
Doruk Can Ogan am 8 Feb. 2018
Beantwortet: Walter Roberson am 9 Feb. 2018
hello everyone,
alpha=t*(2*pi/T) (angular velocity and T is the period=0.02s) (alpha [0 2*pi])
V=5*alpha^2
dVdt=10*alpha*(2*pi/T)
I have a periodic function, the volume changes with alpha and also its derivative with time. I want to solve basically this differential equation dVdt=10*alpha*(2*pi/T) with ode45 solver and at the end of the integration, I should get a solution like below. I know I already have the V=5*alpha^2 solution and I can use module operator. But here I want to know how to do this with ode solver for more complicated equations. Thank you

Antworten (2)

JK
JK am 8 Feb. 2018
Hi,
use the mod-command to account for ther periodicality of t.
tspan=linspace(0,0.08,1000);
[t,y]=ode45(@odefun,tspan,0);
figure
plot(t,y)
ylabel ('V')
xlabel ('t')
function dVdt=odefun(t,~)
T=0.02;
alpha=mod(t,T)*2*pi;
V=5*alpha^2;
dVdt=10*alpha*2*pi/T;
end
though I am not getting V = 200 at t=T. however, this will still produce an ongoing increase of V. If you want to set V back to 0 every T, use a boudary value solver. See example 4 in the tutorial for BV-problems.

Walter Roberson
Walter Roberson am 9 Feb. 2018
No, you cannot do this. The ode*() functions require that the function be continuous, and to have two further derivatives that are continuous (it will usually detect if the first derivative is not continuous, but if the second derivative is not continuous it will probably just give the wrong answer.)
You have to stop the ode at the point of discontinuity and restart it. If your function is periodic in time, then that can be done by setting the tspan to cover just one period at a time. If your boundaries are not easily computed as time, then you need to create an event function that signals termination.

Community Treasure Hunt

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

Start Hunting!

Translated by