Solve function give 2 answers when there should be 1.
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!