solve() gives incorrect answer

9 views (last 30 days)
Jori
Jori on 6 Nov 2012
I am having trouble with the solve() command in Matlab R2012a 64 bit. I will supply an example to show what I mean. I stated the specificiation of my computer as well, I do not know if that is considered useful.
----------------------------
COMPUTER SPECIFICATIONS
----------------------------
Windows 7 Enterprise SP 1
64-bit OS
Intel Core i7-2670QM CPU 2.2 GHz
8,00 GB RAM
----------------------------
EXAMPLE
----------------------------
I have a function
G = (- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2)).
I am interested in the intersection with y = -1.
Both
solve(G+1)
and
solve('(- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2)) == -1')
give me
ans =
1
This is only one of the intersections, as can be seen from the figure below. Does anyone have an idea what I might be overlooking?
Thanks in advance,
Jori
  1 Comment
Walter Roberson
Walter Roberson on 6 Nov 2012
The other solution is the rather messy
69/400 + (1/1200)*3^(1/2)*((27883*(127918+30*315201^(1/2))^(1/3) + 400*(127918+30*315201^(1/2))^(2/3) + 1009600)/(127918 + 30*315201^(1/2))^(1/3))^(1/2) + (1/1200)*6^(1/2)*((27883*(127918 + 30*315201^(1/2))^(1/3) - 200*(127918 + 30*315201^(1/2))^(2/3) - 504800 + 1193127*3^(1/2)*((127918 + 30*315201^(1/2))^(1/3)/(27883*(127918 + 30*315201^(1/2))^(1/3) + 400*(127918 + 30*315201^(1/2))^(2/3) + 1009600))^(1/2)*(127918 + 30*315201^(1/2))^(1/3))/(127918 + 30*315201^(1/2))^(1/3))^(1/2)
... for whatever that is worth ;-)

Sign in to comment.

Accepted Answer

Jonathan Epperl
Jonathan Epperl on 6 Nov 2012
Edited: Jonathan Epperl on 6 Nov 2012
I am astounded... So I am using 2011b on a Mac, but that shouldn't account for the differences. I am getting different results from the ones you are getting.
syms x
G = (- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2))
solve(G+1)
yields
ans =
1
0.80485291557706605237097971857745
0.29354887914157893712269217217225
- 0.20420089735932249474683594537485 + 0.025051677816927281916779859288826*i
- 0.20420089735932249474683594537485 - 0.025051677816927281916779859288826*i
Which is very funny, because the last 3 results correspond to G==1, so they're wrong.
If I change the last line
solve(G+1,'MaxDegree',4)
Then I get
ans =
1
%snipped a very long expression
vpa(ans)
ans =
1.0
0.80485291557706605237097971857745
So now those are the correct expressions.
Then what you posted yields
solve('(- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2)) == -1')
Error using solve>getEqns (line 292)
' (- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2)) == -1 ' is not a valid expression or equation.
Error in solve (line 141)
[eqns,vars,options] = getEqns(varargin{:});
And this here ('==' changed to '=')
solve('(- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2)) = -1')
again yields the 5 solutions from above, including the three wrong ones.
Did you maybe assign some value to x at any point, or did anything else that could lead to such weird behavior? If you issue clear all and type my exact commands, do you get different results?
In any case, two solutions:
  1. Add 'MaxDegree',4 and hope for the best
  2. Use Mathematica or even just Wolfram|Alpha, which solved your example perfectly when I tried it: http://wolfr.am/UvC8yp
  6 Comments
Jori
Jori on 7 Nov 2012
And when I try
>> m = 3; s = 4; solve(G == (2*m-s)/s,'MaxDegree',4)
Error using mupadmex
Internal error with symbolic engine. Please quit and
restart MATLAB.
Error in mupadengine/evalin (line 97)
[res,status] = mupadmex(statement);
Error in mupadengine/feval (line 150)
[S,err] = evalin(engine,stmt);
Error in solve (line 160)
sol = eng.feval('symobj::solvefull',eqns,vars);|
Jonathan Epperl
Jonathan Epperl on 7 Nov 2012
Hm, that is mysterious... Here is what my Matlab does if I enter your commands:
>> syms x real
>> G = (x - (23*x^2)/2 + 1/2)/(10*(x^5)^(1/2))
G =
(x - (23*x^2)/2 + 1/2)/(10*(x^5)^(1/2))
>> m = 1; s = 4; (solve(G - ((2*m-s)/s),'MaxDegree',4))
ans =
5.0935065938427671851921446479193
0.30296905750943425877783588487726
0.22908035767961411609832320482884
- 0.1677780045159077800341518688127 + 0.011755832620508898266757829430043*i
- 0.1677780045159077800341518688127 - 0.011755832620508898266757829430043*i
>> m = 0; s = 4; (solve(G - ((2*m-s)/s),'MaxDegree',4))
ans =
1
% Snip
>> vpa(ans)
ans =
1.0
0.43879264431511722778976907661477
>> m = 3; s = 4; (solve(G - ((2*m-s)/s),'MaxDegree',4))
ans =
5.0935065938427671851921446479193
0.30296905750943425877783588487726
0.22908035767961411609832320482884
- 0.1677780045159077800341518688127 + 0.011755832620508898266757829430043*i
- 0.1677780045159077800341518688127 - 0.011755832620508898266757829430043*i
So I am not seeing the error you are seeing, and instead of yielding too few answers, solve returns wrong ones. And complex ones even after I declared x to be real. (You'll notice I changed your syntax from G == ... to G - ..., my version of the symbolic toolbox doesn't like the '==' and it seems better practice doing that anyway).
Reporting that to The MathWorks seems a good idea. I have 2012b at home, I'll try tonight and see whether that yields yet other results... Apart from hoping the MathWorks to fix anything (or us finding an error in what we are doing), if you have access to Mathematica, or Maple or any other symbolic math software you could try that. Like I said, Wolfram|Alpha (which is free) solved your first problem accurately.

Sign in to comment.

More Answers (1)

Matt Fig
Matt Fig on 6 Nov 2012
Try this way:
>> solve('(- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2))+1')
ans =
1
0.804852915577
0.293548879142
- 0.204200897359 + 0.0250516778169*i
- 0.204200897359 - 0.0250516778169*i
  1 Comment
Jori
Jori on 6 Nov 2012
Edited: Jori on 6 Nov 2012
I tried it, but it does not work. This seems pretty weird.
>> clear all
>> solve('(- 13*x^2 + 2*x + 1)/(10*(x^5)^(1/2))+1')
ans =
1
Could it have to do with the version of Matlab I am using?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!