-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmag.m
37 lines (33 loc) · 994 Bytes
/
mag.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% ------------------------------------------------------------------------------
%
% function mag
%
% this function finds the magnitude of a vector. the tolerance is set to
% 0.000001, thus the 1.0e-12 for the squared test of underflows.
%
% author : david vallado 719-573-2600 30 may 2002
%
% revisions
% vallado - fix tolerance to match coe, eq, etc 3 sep 2002
%
% inputs description range / units
% vec - vector
%
% outputs :
% mag - magnitude
%
% locals :
% none.
%
% coupling :
% none.
%
% mag = ( vec );
% ----------------------------------------------------------------------------- }
function mag = mag ( vec );
temp= vec(1)*vec(1) + vec(2)*vec(2) + vec(3)*vec(3);
if abs( temp ) >= 1.0e-16
mag= sqrt( temp );
else
mag= 0.0;
end