Multiple answers from solve

5 ビュー (過去 30 日間)
Kevin
Kevin 2021 年 9 月 5 日
コメント済み: Kevin 2021 年 9 月 6 日
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?

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 5 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 6 日
Yes, it means thare are two possible answers for alpha.
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 = 
Now let us back-substitute the solutions into the defining equation
subs(eqn1, alpha, sol)
ans = 
lhs(ans) - rhs(ans)
ans = 
The difference between the two sides is 0, for both answers. So both answers are solutions. And MATLAB has no reason to know that one is "right" for your situation unless you give it more information to tell it which one you prefer.
Kevin
Kevin 2021 年 9 月 6 日
Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Symbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by