Why is the lhs function, including the example posted in the MathWorks documentation, not working?

1 view (last 30 days)
As per the first example documentation posted here, the following code does not work correctly for me:
syms x y
eqn = 2*y == x^2;
lhsEqn = lhs(eqn)
Which should result in:
lhsEqn =
2*y
but, instead gives the following error message:
Undefined function 'lhs' for input arguments of type 'logical'.
Error in test (line 3)
lhsEqn = lhs(eqn);
I have tried various rearrengements of the provided example, but all have been unsucessful.
Thanks for any help which you can provide.
  3 Comments
Eric McCormick
Eric McCormick on 8 Jan 2019
Edited: Eric McCormick on 8 Jan 2019
Yes the symbolic toolbox is installed and I do have a valid license (have matlab through my university). Every other function in the Matlab toolbox (excluding lhs and rhs) seems to be working.
Yes I ran that line of code as well, and I also have a clc;clear; in the code at the top, I just copy and pasted the example from the documentation as it was more easily ready for me at the time of asking.
Thanks

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 8 Jan 2019
Apparentlly, MATLAB can’t find the Symbolic Math Toolbox.
First, run these from your Command Window or a script:
restoredefaultpath
rehash toolboxcache
If you still have problems after that, click on the Contact Us link in the top right corner of this page, and request Technical Support.
  2 Comments
Eric McCormick
Eric McCormick on 8 Jan 2019
I think you were right about it having something to do with matlab being unable to find the toolbox, or at least these specific functions (lhs and rhs) because other commands such as subs, solve, sym, syms, etc. were all working for me.
Unfortunetly I was unable to test this as I resorted to a complete MatLab reinstall, but it has solved the issue for me. Purhaps the option you suggested may have been faster than uninstalling and reinstalling, unfortunetly I did not get the opertunity to try.
Thank you for your help,
Eric

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 8 Jan 2019
Edited: madhan ravi on 8 Jan 2019
Might happen in the case that x and y are numeric values hanging in the workspace/global workspace so add clear all/clear global at the beginning and try again:
clear all
clear global
syms x y % requires symbolic math toolbox
eqn = 2*y == x^2;
lhsEqn = lhs(eqn)
To check if you have symbolic math toolbox and license try the below in command window:
ver % symbolic math toolbox should be visible
license('test','symbolic_toolbox') % should return 1
which lhs -all % what does it show?
which rhs -all
  5 Comments
Walter Roberson
Walter Roberson on 25 Jan 2019
In sufficiently old MATLAB, == between two symbolic expressions immediately returned a logical result that indicated whether the two expressions evaluated to the same internal representation. On those versions, == did not even attempt simplification, and was totally unable to prove anything -- and there was also the risk that logically identical expressions written in different order might not come out the same. a + b + c was not certain to == b + c + a for example.
On the other hand, on versions that old, lhs() did not exist yet -- lhs() was not added to MATLAB until several releases after == started being a useful symbolic operation.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!