Access current value ode45
이전 댓글 표시
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
James Tursa
2018년 3월 23일
You need to show more of your code. That small snippet you currently have posted doesn't help us much.
Aarron Sheppard
2018년 3월 23일
Steven Lord
2018년 3월 23일
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
2018년 3월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!