필터 지우기
필터 지우기

How can I solve the periodic function with ode45 solver?

조회 수: 3 (최근 30일)
Doruk Can Ogan
Doruk Can Ogan 2018년 2월 8일
답변: Walter Roberson 2018년 2월 9일
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

답변 (2개)

JK
JK 2018년 2월 8일
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 2018년 2월 9일
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.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by