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 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