Plotting over a Range of Values

4 views (last 30 days)
I'm trying to plot orbital speed and period over a range of altitudes, but I keep getting the following error:
Error using /
Matrix dimensions must agree.
Error in aeroq25 (line 6)
orbital_speed = sqrt(mu_earth*((2/altitude)-(1/altitude))); %km/s
Does anyone have any tips? Here is my code for reference:
altitude = 150:1:1000;
mu_earth = 3.986*10^5; %km3/s2
orbital_speed = sqrt(mu_earth*((2/altitude)-(1/altitude))); %km/s
period = 2*pi*sqrt((altitude^3)/mu_earth); %second
plot(altitude, orbital_speed);

Accepted Answer

Chunru
Chunru on 19 Oct 2021
Use the array operator .* ./ .^2 for arrays.
altitude = 150:1:1000;
mu_earth = 3.986*10^5; %km3/s2
orbital_speed = sqrt(mu_earth*((2./altitude)-(1./altitude))); %km/s
period = 2*pi*sqrt((altitude.^3)/mu_earth); %second
plot(altitude, orbital_speed);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!