ODE45 How to use atmosisa function with Height function as Input?

4 次查看(过去 30 天)
Hello,
I need help to configure how to use atmosisa function if we need to use height function h(t) as input? In this ODE45, I set variable z to be z(1), z(2), z(3) and z(4). z(2) is the height variable. When I put height to be 1000m, the code does work but when I put in as z(2) as input, it gives error.
Density.m
function rho=density()
[~, ~, ~, rho]=atmosisa(z(2));
end
rhs_trajectory
function dz = rhs_trajectory(z,g,F,F_d,m,gamma)
x = z(1);
y = z(2);
v_x = z(3);
v_y = z(4);
dx = v_x;
dy = v_y;
dv_x = ((F-F_d)/m)*cos(gamma)-m*sin(gamma);
dv_y = ((F-F_d)/m)*sin(gamma)-g;
dz = [dx; dy; dv_x; dv_y];
end
I attached other necessery function for reference. Please help me.
  1 个评论
darova
darova 2020-5-27
The question is unclear
  • You are passing some argument into atmosisa, but not passing into density
function rho=density() % z(2) should an argument
[~, ~, ~, rho]=atmosisa(z(2));
end
  • i don't see you use density function. Where do you want to use it?

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2020-5-27
but when I put in as z(2) as input, it gives error
That is most likely because you do not pass it as an argument to your ‘density’ function.
Try this:
function rho=density(x)
[~, ~, ~, rho]=atmosisa(x);
end
(I also do not see where you called it in your ‘rhs_trajectory’ function.)
I do not have the Aerospace Toolbox, so I cannot test this directly. However the problem appears to be obvious.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by