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

11 views (last 30 days)
blackg2
blackg2 on 18 Nov 2015
Answered: Steven Lord on 20 Nov 2015
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?

Answers (2)

Shruti Sapre
Shruti Sapre on 20 Nov 2015
Hi,
I tried running the above functions and it did not give me the 'Output argument "variable" not assigned during call to "function"' error.
1. Can you ensure the exact spelling of the function call?
2. You could initialize all of the output variables (in both functions) at the beginning of the functions so that there is something to return in every case.
3. Add an "else" at the end of the all the conditions for when all of the conditions fail and set "rho" to a value.
4. Try running it after removing the return statement from “LEO_density_range”
5. Stop MATLAB on the last line of the function listed in the warning or error message. Verify that each of the output arguments listed in the function declaration line at the beginning of the function exist after that last line is executed (using the DBSTEP function or the Step button in the Editor).
Hope this helps!
-Shruti

Steven Lord
Steven Lord on 20 Nov 2015
You're assuming that h < 300000. What if it's not? What should LEO_density_range do in that scenario? Walk through the code manually in that scenario, one IF/ELSEIF at a time, and check what it actually does.

Community Treasure Hunt

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

Start Hunting!

Translated by