MATLAB Answers

Classical orbital elements Vectors

34 views (last 30 days)
If I would be given a R and a V vector and I would have to find orbital elements like... (a=semi-major axis)(eccentricity)(inclination)(right ascension of the ascending node)(argument of perigee)(true anomaly). After I defined the vectors and found the magnitudes I was trying to write out my equations but I guess matlab didn't like it. If you could look at my code and point me in the right direction I would appreciate it. I had quite a few of errors just to keep ending my functions over and over again?
First, solve for the angular momentum: h⃗ =r⃗ ×v⃗ h
The eccentricity vector is then: e⃗ =(v2−μ/r)r⃗ −(r⃗ ⋅v⃗ )v⃗
i=cos−1hKhi = cos−1⁡hKh
Ω=cos−1nInΩ = cos−1⁡nIn
ω=cos−1n⃗ ⋅e⃗ neω = cos−1⁡n→⋅e→ne
ν=cos−1e⃗ ⋅r⃗ er
R= [-7953.8073 - 4174.5370 - 1008.9496];
v= [3.6460035 - 4.9118820 - 4.9193608];
nhat=cross([0 0 1],h)
energy = mag(v)^2/2-mu/mag(R)
e = mag(evec)
evec = ((mag(v)^2-mu/mag(R))*R-dot(R,v)*v)/mu
if abs(e-1.0)>eps
a = -mu/(2*energy)
p = a*(1-e^2)
p = mag(h)^2/mu
a = inf
i = acos(h(3)/mag(h))
Omega = acos(n(1)/mag(n))
if n(2)<0
Omega = 360-Omega
argp = acos(dot(n,evec)/(mag(n)*e))
if e(3)<0
argp = 360-argp
nu = acos(dot(evec,R)/(e*mag(R))
if dot(R,v)<0
nu = 360 - nu

Accepted Answer

James Tursa
James Tursa on 3 Mar 2021
Edited: James Tursa on 3 Mar 2021
Use the norm( ) function instead of mag( ). E.g., norm(v) instead of mag(v).
Calculate evec before you calculate e.
Your evec code appears correct, but your description of this is missing the mu term in the denominator. E.g.,
e⃗ =((v2−μ/r)r⃗ −(r⃗ ⋅v⃗ )v⃗ )/μ
James Tursa
James Tursa on 4 Mar 2021
The error message is telling you the exact problem ... you have mismatched parentheses. So add a closing paren:
nu = acos(dot(evec,R)/(e*norm(R)));

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!