Classical orbital elements Vectors
15 views (last 30 days)
Show older comments
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⃗
a=−μ/2E
i=cos−1hKhi = cos−1hKh
Ω=cos−1nInΩ = cos−1nIn
ω=cos−1n⃗ ⋅e⃗ neω = cos−1n→⋅e→ne
ν=cos−1e⃗ ⋅r⃗ er
R= [-7953.8073 - 4174.5370 - 1008.9496];
v= [3.6460035 - 4.9118820 - 4.9193608];
h=cross(R,v);
nhat=cross([0 0 1],h)
r=norm(R);
mu=3.986*10^5
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)
else
p = mag(h)^2/mu
a = inf
end
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))
end
if e(3)<0
argp = 360-argp
nu = acos(dot(evec,R)/(e*mag(R))
end
if dot(R,v)<0
nu = 360 - nu
end
0 Comments
Accepted Answer
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⃗ )/μ
2 Comments
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)));
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing 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!