Solve function give 2 answers when there should be 1.

7 visualizaciones (últimos 30 días)
Sam
Sam el 15 de Oct. de 2020
Comentada: Sam el 17 de Oct. de 2020
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

James Tursa
James Tursa el 15 de Oct. de 2020
Editada: James Tursa el 15 de Oct. de 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.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by