How can I update a variable within an ODE function?

1 回表示 (過去 30 日間)
mjki4hj3
mjki4hj3 2019 年 3 月 6 日
コメント済み: khairul anwar 2021 年 11 月 14 日
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 件のコメント
mjki4hj3
mjki4hj3 2019 年 3 月 6 日
Thank you, this clears up my confusion.
khairul anwar
khairul anwar 2021 年 11 月 14 日
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

サインインしてコメントする。

回答 (1 件)

Ricardo Erazo
Ricardo Erazo 2019 年 3 月 6 日
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 件のコメント
Torsten
Torsten 2019 年 3 月 7 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by