Multiple answers from solve

3 views (last 30 days)
Kevin
Kevin on 5 Sep 2021
Commented: Kevin on 6 Sep 2021
close all
clear
clc
AB=180
AO=60
BO=200
syms alpha
eqn1 = BO^2 == AB^2+AO^2-2*AB*AO*cosd(alpha)
eqn2 = solve (eqn1,alpha)
vpa(eqn2)
ans =
259.32807071423785412135760253313
100.67192928576214587864239746687
I know that it's the latter (100.6719....), but why does it give me 2 answers and how do I make matlab give me 1 answer?

Accepted Answer

Walter Roberson
Walter Roberson on 5 Sep 2021
AB=180
AB = 180
AO=60
AO = 60
BO=200
BO = 200
syms alpha
eqn1 = BO^2 == AB^2+AO^2-2*AB*AO*cosd(alpha)
eqn1 = 
sol = solve(eqn1, alpha)
sol = 
vpa(sol)
ans = 
How is MATLAB to know that one of the solutions is more right than the other?
You could vpasolve() with a range:
vpasolve(eqn1, alpha, [0 180])
ans = 
100.67192928576214587864239746687
  3 Comments
Kevin
Kevin on 6 Sep 2021
Thank you so much.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics 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!

Translated by