Please I need suggesstion on how to solve this problem.
My model is a set of coupled nonlinear and linear ODE and I am running the simulation using ODE23.
I want to open a vent 10 mins (600 secs) after the state variable Z = 10000, at that point the upward_velocity will be theoretically = 0, but in simulation the value of upward_velocity at the targeted Z will vary between (- 0.1 to 0.1).
Usually, the simulation will run for more than 6000 seconds before it attains the point when Z >= 10000. However, the time it runs before it attains this height alto depends on other factors. So the time is not fix.
First, I want to record the time instant (t_z) when Z = 10000 or just greater than 10000. The reason for this condition (Z >= 10000) is that the Z == 10000 may never be achieved.
Secondly, I want to open the vent after 600 seconds.
if Z >= 10000 && Z <= (10000 + tolerance)
if t >= (t_z + 600) && upward_velocity >= -5
venting = - A_ * C1 * sqrt(2*DP * rho);
dM_valve = - rho*A_valve * valve_flow ;
I want to determine if a value has been assigned to t_z or if the variable exist. before implementing the second conditional statement (if t >= (t_z + 600) && upward_velocity >= -5).
So the question is;
- What is the best way to record t_z variable just ones.
- How can I check to see if the variable t_z exist.
I have struggled with this for a couple of days and I will greatly appreciate any help.