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

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 Comment

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?

Sign in to comment.

Answers (1)

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.

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!