solve function give a wrong solution

1 回表示 (過去 30 日間)
Adriano
Adriano 2020 年 7 月 23 日
回答済み: John D'Errico 2020 年 7 月 23 日
Hi all,
I'm trying to solve a simple equation in Matlab using solve function. The code is:
syms x
solv = solve( (1+x/12)^12 == 1.02)
The solution is 0.0204 however Matalb give me this solution:
solv =
- (6*50^(11/12)*51^(1/12))/25 - 12
(6*50^(11/12)*51^(1/12))/25 - 12
- (50^(11/12)*51^(1/12)*6i)/25 - 12
(50^(11/12)*51^(1/12)*6i)/25 - 12
- (6*50^(11/12)*51^(1/12)*(3^(1/2)/2 - 1i/2))/25 - 12
(6*50^(11/12)*51^(1/12)*(3^(1/2)/2 - 1i/2))/25 - 12
- (6*50^(11/12)*51^(1/12)*(3^(1/2)/2 + 1i/2))/25 - 12
(6*50^(11/12)*51^(1/12)*(3^(1/2)/2 + 1i/2))/25 - 12
- (6*50^(11/12)*51^(1/12)*((3^(1/2)*1i)/2 - 1/2))/25 - 12
(6*50^(11/12)*51^(1/12)*((3^(1/2)*1i)/2 - 1/2))/25 - 12
- (6*50^(11/12)*51^(1/12)*((3^(1/2)*1i)/2 + 1/2))/25 - 12
(6*50^(11/12)*51^(1/12)*((3^(1/2)*1i)/2 + 1/2))/25 - 12
>> round(solv)
ans =
-24
0
- 12 - 12i
- 12 + 12i
- 22 + 6i
- 2 - 6i
- 22 - 6i
- 2 + 6i
- 6 - 10i
- 18 + 10i
- 18 - 10i
- 6 + 10i
Why it happen? Someone can help me? Thanks!
  1 件のコメント
KSSV
KSSV 2020 年 7 月 23 日
Why do you think is wrong?

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

採用された回答

Vladimir Sovkov
Vladimir Sovkov 2020 年 7 月 23 日
編集済み: Vladimir Sovkov 2020 年 7 月 23 日
syms x
solv = double(solve( (1+x/12)^12 == 1.02))
There are many solutions. The one you are interested in is rather 0.0198189756230421 but not 0.0204.
  1 件のコメント
Adriano
Adriano 2020 年 7 月 23 日
Sorry I understood...the solutions are correct!

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 7 月 23 日
Just an addendum, though the answer by @Vladimir Sovkov is correct.
Using round to convert those results is wrong. Instead use either double or vpa to do so, depending on whether you want a symbolic or double precision answer. Thus we see:
digits 20
>> vpa(solv)
ans =
-24.019818975623042098
0.019818975623042097611
- 12.0 - 12.019818975623042098i
- 12.0 + 12.019818975623042098i
- 22.40946858177980274 + 6.0099094878115210488i
- 1.5905314182201972597 - 6.0099094878115210488i
- 22.40946858177980274 - 6.0099094878115210488i
- 1.5905314182201972597 + 6.0099094878115210488i
- 5.9900905121884789512 - 10.40946858177980274i
- 18.009909487811521049 + 10.40946858177980274i
- 18.009909487811521049 - 10.40946858177980274i
- 5.9900905121884789512 + 10.40946858177980274i
The second solution is apparently the one you wanted, as has already been shown.

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by