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

1 回表示 (過去 30 日間)
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 件のコメント
Eric McCormick
Eric McCormick 2019 年 1 月 8 日
編集済み: Eric McCormick 2019 年 1 月 8 日
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
Walter Roberson
Walter Roberson 2019 年 1 月 25 日
Note that lhs() was not added until R2017a.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2019 年 1 月 8 日
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 件のコメント
Eric McCormick
Eric McCormick 2019 年 1 月 8 日
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

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 8 日
編集済み: madhan ravi 2019 年 1 月 8 日
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 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 9 日
Completely agree with Steven Lord.
Walter Roberson
Walter Roberson 2019 年 1 月 25 日
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.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by