Output argument "variable" (and maybe others) not assigned during call to "function".

3 ビュー (過去 30 日間)
blackg2
blackg2 2015 年 11 月 18 日
回答済み: Sriram Tadavarty 2022 年 6 月 4 日
I'm creating a program that models the flight path of a satellite in low earth orbit, where the changing densities is necessary to compute the drag forces. My function for calculating the drag forces is as follows:
function [ax,ay] = LEO_drag_acceleration(x,y,vx,vy,g)
C_d = 2.2;
h = y;
A = .3;
vel = sqrt(vx.^2 + vy.^2);
rho = LEO_density_range(h);
ax = -((rho*C_d*A)/2)*vel*vx;
ay = -g-((rho*C_d*A)/2)*vel*vy;
return
end
and the LEO_density_range function is as follows:
function rho = LEO_density_range(h)
if h < 25000
rho = 1.225;
elseif h >= 25000 && h < 30000;
rho = 3.899*10^-2;
elseif h >= 30000 && h < 40000;
rho = 1.744*10^-2;
elseif h >= 40000 && h < 50000;
rho = 3.972*10^-3;
elseif h >= 50000 && h < 60000;
rho = 1.057*10^-3;
elseif h >= 60000 && h < 70000;
rho = 3.206*10^-4;
elseif h >= 70000 && h < 80000;
rho = 8.770*10^-5;
elseif h >= 80000 && h < 90000;
rho = 1.905*10^-5;
elseif h >= 90000 && h < 100000;
rho = 3.396*10^-6;
elseif h >= 100000 && h < 110000;
rho = 5.297*10^-7;
elseif h >= 110000 && h < 120000;
rho = 9.661*10^-8;
elseif h >= 120000 && h < 130000;
rho = 2.438*10^-8;
elseif h >= 130000 && h < 140000;
rho = 8.484*10^-9;
elseif h >= 140000 && h < 150000;
rho = 3.845*10^-9;
elseif h >= 150000 && h < 180000;
rho = 2.070*10^-9;
elseif h >= 180000 && h < 200000;
rho = 5.465*10^-10;
elseif h >= 200000 && h < 250000;
rho = 2.789*10^-10;
elseif h >= 250000 && h < 300000;
rho = 7.248*10^-11;
return
end
Any ideas on how to solve this issue?
This is the actual error message: "Output argument "rho" (and maybe others) not assigned during call to "LEO_density_range"."

回答 (1 件)

Sriram Tadavarty
Sriram Tadavarty 2022 年 6 月 4 日
Hi blackg2,
Based on the error message and the code provided, it is possible that the when the value of h is greater than or equal to 300000, the function doesn't assign rho, since there is no condition in the code which assign rho for those values. I think the function LEO_density_range is getting called with h greater than 300e3 and due to which the error is observed.
You can try to assign a default value in case any of the condition is not satisfied and also, the return call in the last elseif statement is not required.
Sample code:
if cond1
elseif cond2
else
% Default case
rho = 5e-12; % some value
end
Adding the above else case would avoid the error.
Hope this helps.
Regards,
Sriram

カテゴリ

Help Center および File ExchangeReference Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by