Solve function give 2 answers when there should be 1.

9 次查看(过去 30 天)
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!

采纳的回答

James Tursa
James Tursa 2020-10-15
编辑:James Tursa 2020-10-15
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by