"solve " function returns inaccurate solutions
Mostra commenti meno recenti
Hi.
I tried to solve the following equation with "solve" command:
x-[\sqrt{x+1}+\sqrt{x-1}] = 0
I entered the following command:
solve('x-sqrt(x+1)-sqrt(x-1)','x')
and recieved 4 solution, one of them was, "1.11508....", which is not correct. there was also the correct solution between the answers , which is 3.9343...
what's the problem, how can I trust the answers produced by commands such as 'solve' command ?
Thanks alot.
Risposta accettata
Più risposte (4)
Birdman
il 21 Gen 2019
Try this:
syms x
assume(x,'real');
solx=vpasolve(x-sqrt(x+1)-sqrt(x-1)==0,x)
or
syms x
assume(x,'real');
solx=vpa(solve(x-sqrt(x+1)-sqrt(x-1)==0,x))
You can tell MATLAB that you want x variable to be assumed as a real number.
6 Commenti
Torsten
il 21 Gen 2019
This doesn't answer the question why x=1.11508... is returned as a solution.
moh pouladin
il 21 Gen 2019
Walter Roberson
il 21 Gen 2019
You are either using R2011b or earlier, or you are using the Maple based symbolic toolbox.
You might be able to use
syms x real
moh pouladin
il 21 Gen 2019
Walter Roberson
il 21 Gen 2019
For your release, leave out the ==0
syms x real
solx=vpa(solve(x-sqrt(x+1)-sqrt(x-1),x))
moh pouladin
il 21 Gen 2019
madhan ravi
il 21 Gen 2019
fzero(@(x)x-sqrt(x+1)-sqrt(x-1),[1 5])
% ^^^----- domain
%or
syms x
sol=vpasolve(x-sqrt(x+1)-sqrt(x-1)==0,x,[1 5])
3 Commenti
moh pouladin
il 21 Gen 2019
Modificato: moh pouladin
il 21 Gen 2019
madhan ravi
il 21 Gen 2019
Modificato: madhan ravi
il 21 Gen 2019
You seem to be using 2011b version and vpasolve() was introduced in 2012b , plus in later release the correct is being observed . Try clear all and clear global at the very beginning and try your original code again.
moh pouladin
il 21 Gen 2019
Walter Roberson
il 21 Gen 2019
syms x
solve(x-sqrt(x+1)-sqrt(x-1),'maxdegree', 4)
You will get the solution,
((9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3) - 3*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3) - 20)^(1/2)/(6*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/6)) + (20*(9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3) - 3*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3) - 20)^(1/2) - 6*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3)*(9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3) - 3*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3) - 20)^(1/2) - 9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3)*(9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3) - 3*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3) - 20)^(1/2) + 6*2^(1/2)*6^(1/2)*(3*3^(1/2)*23^(1/2) + 11)^(1/2))^(1/2)/(6*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/6)*(9*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(2/3) - 3*((4*3^(1/2)*23^(1/2))/9 + 44/27)^(1/3) - 20)^(1/4)) + 1/2)^2 + 1
simplify(expand()) will give you a slightly more compact version of it.
6 Commenti
moh pouladin
il 21 Gen 2019
madhan ravi
il 21 Gen 2019
post the screenshot of the results that you got
John D'Errico
il 21 Gen 2019
What MATLAB release?
moh pouladin
il 21 Gen 2019
moh pouladin
il 21 Gen 2019
Walter Roberson
il 21 Gen 2019
Possibly you need
syms x
solve(x-sqrt(x+1)-sqrt(x-1), x, 'maxdegree', 4)
'maxdegree' is a valid option for your release, provided you are not using the Maple based symbolic engine.
John D'Errico
il 21 Gen 2019
Modificato: John D'Errico
il 21 Gen 2019
Works for me:
syms x
S = solve(x-sqrt(x+1)-sqrt(x-1))
S =
root(z^4 - 2*z^3 + 2*z^2 - 2*z - 1, z, 4)^2 + 1
vpa(S)
ans =
3.9343171651798551019840207842855
If you use 'maxDegree' as 4, as Walter suggests, you get an analytical expression, as he shows. But either way does give you the correct solution.
If you get something else, what MATLAB release are you using? My guess it it is an old release, since it accepts string input for the equation. One of the things we have been asking for is a flag when you post an answer, that tells readers which MATLAB release you are using. That would more easily help to resolve such issues.
Categorie
Scopri di più su Operations on Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



