Access current value ode45
Ältere Kommentare anzeigen
Hi guys, I'm currently working on an assignment where I need to use ODE45. I have 4 equations to solve, which are linked to each other. The relevant section of the function i'm giving to ode45 looks somewhat like this:
[t,x]=ode45(@(t,x) rocketEqns(A,T,g0,m0,cd,rho0,me,htower,hscale,t),[t0 tbo],Initvals);
function[Variables]=rocketEqns(A,T,g0,m0,cd,rho0,me,htower,hscale,t)
%it is important that the rocket remains at a pitch angle of 89.85 degrees
%until past the tower height, ie alt>htower;
Variables=[0 0 0 0]'; %h,v,gamma,x
g=g0/((1+(Variables(1)/6378000))^2);
rho=rho0*exp((-1*Variables(1))/hscale);
q=0.5*rho*(Variables(2)^2);
D=q*A*cd;
if Variables(1)<htower
Variables(3)=0;
Variables(2)=(T-D-((m0-(me*t)))*g*sin(Variables(3))/(m0-(me*t)));
Variables(1)=Variables(2);
Variables(4)=0;
else
Variables(3)=(-g*cosd(Variables(3))/Variables(2));
Variables(2)=(T-D-((m0-(me*t)))*g*sin(Variables(3))/(m0-(me*t)));
Variables(1)=Variables(2)*sind(Variables(3));
Variables(4)=Variables(2)*cosd(Variables(3));
end
end
ie if the 1st variable is less than 90 then the second variable doesn't change, if the first variable is greater than 90 then the second variable changes by whatever is calculated inside the function. What I think is actually happening is that this is evaluating whether the rate of change of variable(1) is less than 90.
How do i access the current value? I tried getting it from the output but it gave me an error.
Thanks in advance
4 Kommentare
James Tursa
am 23 Mär. 2018
You need to show more of your code. That small snippet you currently have posted doesn't help us much.
Aarron Sheppard
am 23 Mär. 2018
Steven Lord
am 23 Mär. 2018
In addition to the other comments or answers, this section of your code is suspicious.
Variables(2)=(T-D-((m0-(me*t)))*g*sin(Variables(3))/(m0-(me*t)));
Variables(1)=Variables(2)*sind(Variables(3));
Is Variables(3) an angle in degrees (in which case both lines should use sind) or an angle in radians (in which case both should use sin)?
Aarron Sheppard
am 24 Mär. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!