Solve function give 2 answers when there should be 1.

9 views (last 30 days)
My question is why the solve function returns 2 values for acos()? I'm trying to get MATLAB to solve Kepler's trajectory equation (where theta - theta0 = f1 in this case) for f1. Done manually, I get 1 answer: f1 = 2.3583 rad, but solve() returns 2 answers: 3.9249 and 2.3583. If I don't double check my answer, I might choose the wrong output. Why does MATLAB do this and how do I resolve it, or how do I know without that extra verification step which solution MATLAB gives is the correct one? It's not always the first or second element in the array, because the same exact code put in another script where r, p, and e are not hard-coded returns these 2 values switched.
----- code -----
-------------------------------------------
% example
clc;
clear all;
r = 6707.614926;
p = 5759.485421;
e = 0.19948067;
syms f1_var
eq = r == p/(1+e*cos(f1_var));
ans = solve(eq,f1_var);
f1_auto = double(ans)
f1_man = acos((1/e)*(p/r-1))
-------------------------------------------
----- results -----
f1_auto =
2.3583
3.9249
f1_man =
2.3583
-------------------------------------------
Thank you so much!

Accepted Answer

James Tursa
James Tursa on 15 Oct 2020
Edited: James Tursa on 15 Oct 2020
For a generic orbit problem, i.e. an ellipse, there are always going to be two places on the orbit path with the same r value (except for the perigee and apogee points). One outgoing and one incoming. MATLAB is simply giving you both valid solutions. It is up to you to determine which one you want ... MATLAB has no way of knowing. They are both "correct" as far as solving the equation is concerned.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!