How to code a pulse function in differential equations

35 vues (au cours des 30 derniers jours)
Rui
Rui le 10 Jan 2017
Commenté : 태훈 le 25 Avr 2024 à 7:54
Hello everyone,
could you help me with my problem described below?
assuming I have a simple model dX/dt = -k*X/V, where X is amount, t is time (between 0 and 24 hours), V is volume, and k is rate.
I would like to add a certain amount of mass (M) into my system every 1 hour, in other words, adding mass on 1, 2, 3...23 hour. It does not need to be exactly on every hour, but could be a small interval (tau) around 1, 2, 3, ... so equation becomes something like
dX/dt = -k*X/V + M/tau, M is zero when t is out of these small intervals.
I just cannot figure out a smart way to code this, and then solve the ODE. Could you give me some idea? Thanks in advance!
Rui
  1 commentaire
태훈
태훈 le 25 Avr 2024 à 7:54
If you can't get explicit solutions, I guess you could try "a series of odes" using a for loop. For example,...
tv=[0:1:100]
y0=1
for k=1:length(t)-1
tspan=[tv(k), tv(k+1)];
[t,y]=ode45(@yourfun, tspan...)
y0=y(length(y))+1 % e.g., adding 1 at every 1 hour
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by