How can I update a variable within an ODE function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to update the value of yprime within the ODE function 'odes'
Function call:
bc = [1 0.2050 0.3 0.1468];
options = bvpset('RelTol', 1e-07);
[z,y] = ode15s(@odes, [0 10], bc, options);
plot(z,y)
Inside ODE function:
function f =odes(z,y)
%parameters
K1 = 8.8721e-7; K2 = -1.4715e-03; alpha = 5.4;
%alegbraic equation relying on solving of ODEs
yprime = (1+(alpha-1)*(y(2)+y(4))-((1+(alpha-1)*(y(2)+y(4)))^2-4*alpha*(alpha-1)*y(4)*y(2))...
^0.5)/(2*(alpha-1)*y(4))
%system of ODEs
f(1) = -K1*(alpha*(1-y(2))*(y(2)-y(4)*yprime)-y(2)*((1-y(2))-y(4)*(1-yprime)));
f(2) = -K1*(alpha*(1-y(2))*(y(2)-y(4)*yprime)-y(2)*((1-y(2))-y(4)*(1-yprime)));
f(3) = (-K1*(alpha*(1-y(2))*(y(2)-y(4))*yprime)-y(2)*((1-y(2))-y(4)*(1-yprime)))/y(1);
f(4) = K2*y(3)/y(4);
end
I have a system of ODEs and one algebraic equation that relies on the output of the ODE. I have an initial value yprime but I'm not sure how to incoporate this into the above expression.
7 commentaires
khairul anwar
le 14 Nov 2021
I have the same problem where i need to put all the different result from different values of alpha in one figure. Can anybody help me..I really appreciate that
Réponses (1)
Ricardo Erazo
le 6 Mar 2019
These do not answer the question. How can someone update the variable insid the function?
I have a 5 variable system, I need to update the value of y(5) whenever y(1) crosses a threshold. The best solution thus far is to stop integration, reset value outside of the function, and then call the function again. Are there any more efficient methods?
1 commentaire
Torsten
le 7 Mar 2019
No. Using MATLAB's event detection is the best way to go.
For an example, take a look at
https://www.mathworks.com/examples/matlab/mw/matlab-ex84325677-simple-event-location-a-bouncing-ball
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations 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!