number format using solve

Why when I use (solve) for quadratic equations I get This format numbers, Example:
solve(X^3+X-2==0)
ans =
1
- (7^(1/2)*1i)/2 - 1/2
(7^(1/2)*1i)/2 - 1/2
or sometimes the number will be so long
- (288230376151711744*889388876854208557621367400315380756942440049^(1/2))/1299318122813130077998372749837905 - 66276228678941179381385795875815555072/1299318122813130077998372749837905
(288230376151711744*889388876854208557621367400315380756942440049^(1/2))/1299318122813130077998372749837905 - 66276228678941179381385795875815555072/1299318122813130077998372749837905

Réponses (2)

KSSV
KSSV le 16 Juil 2019

0 votes

REad about double and vpasolve
Walter Roberson
Walter Roberson le 16 Juil 2019

0 votes

Why not? Those are the answers to the question you are asking of MATLAB. If you put them back through the equations, you will find that they are correct.
The goal of solve is to find exact closed form solutions whenever possible, preferably algebraic numbers. The results you are getting back are algebraic numbers.
Perhaps you were expecting results closer to:
>> roots([1 0 1 -2])
ans =
-0.5 + 1.3228756555323i
-0.5 - 1.3228756555323i
1 + 0i
However, those are not exact solutions, only approximations:
>> ans.^3 + ans - 2
ans =
-1.55431223447522e-15 - 2.22044604925031e-16i
-1.55431223447522e-15 + 2.22044604925031e-16i
8.88178419700125e-16 + 0i
Notice that back substituting does not give exact zeros -- because the numeric approximations are not exact solutions.
If you are looking for numeric solutions then use roots() or use vpasolve()
>> vpasolve(X^3+X-2==0)
ans =
1.0
- 0.5 - 1.3228756555322952952508078768196i
- 0.5 + 1.3228756555322952952508078768196i

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by