ODE45 with state dependent parameter
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone,
I'm trying to solve a simple 2d thrust-vector control problem using ODE45. So basically I have my function:
function drdt = odefun(t,r,m_0,m_f,m_dot,T_0,g,beta_0,l)
if t < 100
m = m_0 + (m_f - m_dot * t);
T = T_0;
else
m = m_0;
T = 0;
end
drdt = [r(2);
T/m*(cos(beta)*cos(r(5)) + sin(beta)*sin(r(5)));
r(4);
T/m*(cos(beta)*sin(r(5)) + sin(beta)*cos(r(5))) - g;
r(6);
12*l*T*sin(beta)/m];
end
where beta is the angle of an engine tilt and what I am trying to do is to tilt it for a while. As long as this parameter is time-dependent everything works fine (I put it in the function):
if (t > 30) && (t < 35)
beta = beta_0;
else
beta = 0;
end
but when I try to make it altitude-dependent something strange happens. If I set the altitude range as (1000;1800) it works fine:
if (r(3) > 1000) && (r(3) < 1800)
beta = beta_0;
else
beta = 0;
end
nevertheless when I make it a bit smaller for example (1000;1500) the condition is never met although in the results it reaches these altitudes for several timesteps. I know I can solve this problem by using events functionality but I in the future I would like to make this tilt to adjust every iteration so it doesn't seem like a good idea. How can I overcome this?
0 Commenti
Risposte (1)
Prannoy
il 30 Giu 2023
It seems like you are facing an issue with the condition not being met when you make the altitude range smaller. One possible reason for this behavior could be the discrete nature of the simulation, where the altitude might not exactly match the specified range at each time step. To overcome this issue, you can introduce a tolerance in your condition to account for small deviations in the altitude.
Instead of using strict inequality, you can modify your condition as follows:
if (r(3) > 1000 - tolerance) && (r(3) < 1500 + tolerance)
beta = beta_0;
else
beta = 0;
end
Here, tolerance is a small positive value that allows for some flexibility in the altitude condition. You can experiment with different values of tolerance to find a suitable range that captures the desired altitude range accurately.
By introducing this tolerance, you can account for small deviations in the altitude and ensure that the condition is met within the desired range, even if the exact altitude is not reached at each time step.
0 Commenti
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!