finding magnitude of a vector
20 views (last 30 days)
Show older comments
Hi all, I am trying to make a function and the first step within my function is to find the magnitude of a vector that I have named on another script. How do I do this? I willo put my code below to explain more.
FROM FUNCTION PAGE
function[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(R, V)
% Inputs
% R = Radius vector [km]
% V = Velocity vector [km/s]
%
% Outputs
% a = semi major axis [km]
% e = eccentricity [no units]
% nu = true anomoly [degrees]
% i = inclination [degrees]
% O = right ascention of the ascending node(RAAN) [degrees]
% w = argument of perigee [degrees]
% Known values
m = 398600; % [km^3/s^2]
% Step one find the magnitude of the radius and velocity vectors
r = norm(R);
v = norm(V);
FROM SCRIPT
% Create a structure for our function to find COE parameters
Rvector = [15370 1400 21950]; % [km]
Vvector = [-0.1 3.84 -0.2]; % [km/s]
% Call function with the structured variables we created above
[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(Rvector, Vvector);
so to reiterate my question, how do I find the magnitude of Rvector that is defined in my script on my function page (STEP ONE IN FUNCTION)
16 Comments
VBBV
on 8 Nov 2020
Edited: VBBV
on 8 Nov 2020
Check the syntax of function declaration. You require space between the word function and output variable vector
%if true
% code
%end
function [a,e,nu,i,O,m]=
w_COE_sharmaAshlianne(Rvector,Vvector)
...
r = norm(Rvector);
v = norm(Vvector)
...
end % close function file with end statement
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!