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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Eric McCormick
Eric McCormick am 8 Jan. 2019
Bearbeitet: Eric McCormick am 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Eric McCormick
Eric McCormick am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 8 Jan. 2019
Bearbeitet: madhan ravi am 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 Kommentare
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by