Info

此问题已关闭。 请重新打开它进行编辑或回答。

how to fix a value in a function during an ode integration, that does not change during the integration

1 次查看(过去 30 天)
hi all,
I have to fix a value during an ode integration:
if z > 1000
dx = v*cos(gamma)*cos(chi);
dy = v*cos(gamma)*sin(chi);
dz = v*sin(gamma);
elseif z <= 1000
x_scalato = 22991;
xD = x_scalato + 1e3 * [0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5];
AD = [-50 -45 -35 -20 -10 5 20 30 40 50 50];
BD = [0 -5 -25 -45 -50 -50 -50 -30 -5 0 0];
lambda = 0.1;
h_star = 1000;
A_ws = interp1(xD,AD,x,'spline');
B_ws = interp1(xD,BD,x,'spline');
Wx = lambda * A_ws;
Wy = lambda * A_ws;
Wh = lambda * z/h_star * B_ws;
dx = v*cos(gamma)*cos(chi) + Wx;
dy = v*cos(gamma)*sin(chi) + Wy;
dz = v*sin(gamma) + Wh;
end
in ode function I have this if cycle where in the elseif statement there is an interpolation
I have to remove the hard code value
x_scalato = 22991;
x_scalato is the value of x as soon as z is less then 1000, so when there is the elseif statement.
this value is computed during the FIRST cycle of integration and remain constant, so for all the remain part of integration remain the same.
Can you help me to do this ?
Many thank for your time and consideration

回答(1 个)

Matt J
Matt J 2020-10-13
  1 个评论
J. Alex Lee
J. Alex Lee 2020-10-13
i believe the issue is that the value must be generated during an early stage of the integration.
But to your point, a valid strategy may be to split the integration into 2 steps, one of them up to the event, at which time the value of interest can be extracted as an output, and then passed as an extra argument to the second separate integration.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by