symbolic solver strikes again!

4 views (last 30 days)
Robert
Robert on 19 Jul 2016
Commented: Walter Roberson on 5 Jan 2022
Someone please tell me why this doesn't work.
I have used symbolic solver many times and every time i do i end up wishing i pulled out my ti89 and been done with it. I waste more time messing with this then its worth
Example code to confirm it works
syms x
eqn = sin(x) == 1;
%%just for confirmation
eqn
eqn =
sin(x) == 1
solx = solve(eqn,x)
solx =
pi/2
Very simple obviously
Now again
equation = exp(x/.2968)/exp(227.1692/.2968) == 9/2;
equation
equation =
0 == 9/2
How is my equation now
0 == 9/2
??????????
Also another version i have tried that used to work all the time and no longer does
syms x
solve(900/200 == exp(x/.2968)/exp(227.1692/.2968) ,x)
ans =
Empty sym: 0-by-1
Obviously the answer is now a 0X1 matrix

Answers (1)

Walter Roberson
Walter Roberson on 19 Jul 2016
Edited: Walter Roberson on 19 Jul 2016
Remember that floating point expressions are calculated in floating point before the expression is sent to the symbolic engine, and that at the time you send to the symbolic engine all remaining floating point values are converted to rational.
If you are more careful about the conversion then you can get a solution:
Q = @(v) sym(v); %converts value to symbolic rational number
solve(Q(900)/Q(200) == exp(x/Q(.2968))/exp(Q(227.1692)/Q(.2968)) ,x)
ans =
(371*log((9*exp(47127391862749375/61572651155456))/2))/1250
you can then simplify(ans) to get something more compact.
In particular you are getting floating point overflow when you calculate exp(227.1692/.2968) in floating point.
In the first equation, you are dividing by that inf. exp(x/.2968) is treated as "some non-zero value" (x would have to be -inf for the exp() to become 0), and a non-zero value divided by inf is 0 . The left side of your first equation thus becomes 0.
My rule of thumb is to never use floating point quantities in a symbolic expression; I always convert them to rational on input, to avoid these kinds of numeric problems.
  6 Comments
Chris Gorden
Chris Gorden on 5 Jan 2022
This is an excellent explanation W.R. and thank you for taking the time to describe the situation in such detail. I believe that I originally came across this thread a few months to a year a ago, when I ran into similar issues using Symbolics in Live Scripts.
I've never actually used MuPad because when you ener the command in 2019b+ a pop-up informs you that Live Scripts will ultimately replace Mupad. I really enjoy Live Script but it is definitely not a purely symbolic environment, as you have described Mupad. It seems that all of the additional precautions that you describe are still necessary in the Live Script.
So my question to you, or anyone paying attention to this somewhat dated thread: Is there a way to get a Live Script to be a symbolic environment in the way that MuPad apparently functioned?
While I know this is not currently the case, my dream solution would be something like a "format symbolic" command.
Walter Roberson
Walter Roberson on 5 Jan 2022
Unfortunately, no. About the closest you can get is to str2sym() every expression.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!