Why are symbolic variables not allowed when using the functions MAX/MIN in the Symbolic Math Toolbox V 5.2 (R2009a)?

2 Ansichten (letzte 30 Tage)
I have some symbolic variables and would like to find the minimum values in them:
syms x y
min(x,y)
I receive the following error:
??? Function 'min' is not defined for values of class 'sym'.
When using ABS function for a symbolic variable, I receive the correct answer:
syms x
abs(x)
The same is true for MAX.
Also for numerical comparisons this error occurs:
syms x
max(x,-1)

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 26 Aug. 2009
The ability to use the functions MAX and MIN for objects of class 'sym' is not available in MATLAB.
To work around this issue, you could do one of the following, depending on the definition of the symbolic variables:
1. For symbolic comparisons there is no general workaround as there is no clear definition of what the result should look like. An example shows quite clearly the lack of a definition of a "good" result.
% This code will not work
syms x1 x2 x3 x4 x5
X = [x1,x2,x3,x4,x5];
max(X)
min(X)
% also unclear:
x1 > x2
x4 < x3
If the ranges of the symbolic variables being compared are clearly separated, the function FEVAL can be used as follows:
syms x positive;
syms y positive;
feval(symengine,'max',x,-y)
Similarly, a comparison can be made between a symbolic variable and a double using the function FEVAL
syms x positive
feval(symengine,'max',x,-1)
This will return "x" as x would be always greater 0 and therefore greater -1.
2. If you have an array of symbolic numbers like
X = sym([1,2,3,4]);
then the array can be cast to type DOUBLE before using the function MAX/MIN on it. E.g.
max(double(X))

Weitere Antworten (0)

Produkte


Version

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by