Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Get a strange error while use 'min' function for 'sym'

Subject: Get a strange error while use 'min' function for 'sym'

From: mango

Date: 9 Apr, 2009 05:41:45

Message: 1 of 5

Hi, All.
  I've got a problem like this:
      input some insturctions like
                syms x y
                min(x,y)
   in the workspace.Then get the following error :

??? Function 'min' is not defined for values of class 'sym'.

Error in ==> min at 34
  builtin('min', varargin{:});

In the other side, I try to use abs function like this,
                syms x
                abs(x)
Then get the correct answer.How to solve this probelm?

pls help me ,thank you in advance.

Subject: Get a strange error while use 'min' function for 'sym'

From: Roger Stafford

Date: 9 Apr, 2009 06:11:04

Message: 2 of 5

mango <sniperhunters@gmail.com> wrote in message <4b464a96-bf26-49fe-82ec-dd821145cb3e@z9g2000yqi.googlegroups.com>...
> Hi, All.
> I've got a problem like this:
> input some insturctions like
> syms x y
> min(x,y)
> in the workspace.Then get the following error :
>
> ??? Function 'min' is not defined for values of class 'sym'.
>
> Error in ==> min at 34
> builtin('min', varargin{:});
>
> In the other side, I try to use abs function like this,
> syms x
> abs(x)
> Then get the correct answer.How to solve this probelm?
>
> pls help me ,thank you in advance.

  Think about it, Mango. What answer can you expect out of min(x,y) when x and y are merely symbols whose values cannot be compared numerically. Matlab could answer: "Duh! Ya got me!" but I don't think users would like that very much. Much better to respond with an error indication.

Roger Stafford

Subject: Get a strange error while use 'min' function for 'sym'

From: mango

Date: 9 Apr, 2009 07:21:07

Message: 3 of 5

On 4=D4=C29=C8=D5, =CF=C2=CE=E72=CA=B111=B7=D6, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> mango <sniperhunt...@gmail.com> wrote in message <4b464a96-bf26-49fe-82ec=
-dd821145c...@z9g2000yqi.googlegroups.com>...
> > Hi, All.
> > I've got a problem like this:
> > input some insturctions like
> > syms x y
> > min(x,y)
> > in the workspace.Then get the following error :
>
> > ??? Function 'min' is not defined for values of class 'sym'.
>
> > Error in =3D=3D> min at 34
> > builtin('min', varargin{:});
>
> > In the other side, I try to use abs function like this,
> > syms x
> > abs(x)
> > Then get the correct answer.How to solve this probelm?
>
> > pls help me ,thank you in advance.
>
> Think about it, Mango. What answer can you expect out of min(x,y) when=
 x and y are merely symbols whose values cannot be compared numerically. M=
atlab could answer: "Duh! Ya got me!" but I don't think users would like th=
at very much. Much better to respond with an error indication.
>
> Roger Stafford- =D2=FE=B2=D8=B1=BB=D2=FD=D3=C3=CE=C4=D7=D6 -
>
> - =CF=D4=CA=BE=D2=FD=D3=C3=B5=C4=CE=C4=D7=D6 -

Dear Roger, thanks for your answer,

I just want to use 'min' function to produce a kernel function, like a
spline function:
                   1 + x*y + 1/2*|x-y|*(x/\y)^2 + 1/3*(x/\y)^3
Here 'x/\y' means min(x,y).
In matlab, I define an anonymous function like this,
                   fun =3D @(x,y) (1 + x * y + 1/2 * abs(x-y)*min(x,y)^2
+ 1/3 * min(x,y)^3)
Then I define a 'sym' variouble x to calculate it(here 'y' is a
constant).And get the error like that
" ??? Function 'min' is not defined for values of class 'sym' ".

I've understood your meaning that 'min(x,y)' can't use in 'sym'
because they are symbols, but now I wanna to calculate the function.
Can any other functions or instruments take the similar operation like
'min()' in my situation.

Subject: Get a strange error while use 'min' function for 'sym'

From: Steven Lord

Date: 9 Apr, 2009 13:49:19

Message: 4 of 5


"mango" <sniperhunters@gmail.com> wrote in message
news:75a53998-b9fd-4d15-b24b-4775a39c89bd@k8g2000yqn.googlegroups.com...
On 4

Subject: Get a strange error while use 'min' function for 'sym'

From: mango

Date: 10 Apr, 2009 01:28:08

Message: 5 of 5

On 4=E6=9C=889=E6=97=A5, =E4=B8=8B=E5=8D=889=E6=97=B649=E5=88=86, "Steven L=
ord" <sl...@mathworks.com> wrote:
> "mango" <sniperhunt...@gmail.com> wrote in message
>
> news:75a53998-b9fd-4d15-b24b-4775a39c89bd@k8g2000yqn.googlegroups.com...
> On 4=C3=94=C3=829=C3=88=C3=95, =C3=8F=C3=82=C3=8E=C3=A72=C3=8A=C2=B111=C2=
=B7=C3=96, "Roger Stafford"
>
>
>
>
>
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> > mango <sniperhunt...@gmail.com> wrote in message
> > <4b464a96-bf26-49fe-82ec-dd821145c...@z9g2000yqi.googlegroups.com>...
> > > Hi, All.
> > > =C2=A0 I've got a problem like this:
> > > =C2=A0 =C2=A0 =C2=A0 input some insturctions like
> > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 syms x y
> > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 min(x,y)
> > > =C2=A0 =C2=A0in the workspace.Then get the following error :
>
> > > ??? Function 'min' is not defined for values of class 'sym'.
>
> > > Error in =3D=3D> min at 34
> > > =C2=A0 builtin('min', varargin{:});
>
> > > In the other side, I try to use abs function like this,
> > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 syms x
> > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 abs(x)
> > > Then get the correct answer.How to solve this probelm?
>
> > > pls help me ,thank you in advance.
>
> > =C2=A0 Think about it, Mango. =C2=A0What answer can you expect out of m=
in(x,y) when
> > x and y are merely symbols whose values cannot be compared numerically.
> > Matlab could answer: "Duh! Ya got me!" but I don't think users would li=
ke
> > that very much. =C2=A0Much better to respond with an error indication.
>
> > Roger Stafford- =C3=92=C3=BE=C2=B2=C3=98=C2=B1=C2=BB=C3=92=C3=BD=C3=93=
=C3=83=C3=8E=C3=84=C3=97=C3=96 -
>
> > - =C3=8F=C3=94=C3=8A=C2=BE=C3=92=C3=BD=C3=93=C3=83=C2=B5=C3=84=C3=8E=C3=
=84=C3=97=C3=96 -
>
> > Dear Roger, thanks for your answer,
>
> > I just want to use 'min' function to produce a kernel function, like a
> > spline function:
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A01 =
+ x*y + 1/2*|x-y|*(x/\y)^2 + 1/3*(x/\y)^3
> > Here 'x/\y' means min(x,y).
> > In matlab, I define an anonymous function like this,
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fu=
n =3D @(x,y) (1 + x * y + 1/2 * abs(x-y)*min(x,y)^2
> > + 1/3 * min(x,y)^3)
> > Then I define a 'sym' variouble x to calculate it(here 'y' is a
> > constant).And get the error like that
> > " ??? Function 'min' is not defined for values of class 'sym' ".
>
> > I've understood your meaning that 'min(x,y)' can't use in 'sym'
> > because they are symbols, but now I wanna to =C2=A0calculate the functi=
on.
> > Can any other functions or instruments take the similar operation like
> > 'min()' in my situation.
>
> Evaluate the anonymous function you created for numeric values of x and y=
.
>
> x =3D 5;
> y =3D 6;
> fun(x, y)
>
> If you vectorize your anonymous function (using .* and .^ instead of * an=
d
> ^) you can even call it with a vector or matrix of x and y values.
>
> fun =3D @(x, y) (1+x.*y + 1/2*abs(x-y).*min(x, y).^2 + 1/3*min(x, y).^3);
> x =3D 1:10;
> y =3D 1:10;
> fun(x, y)
>
> I didn't use .* when multiplying 1/2 and 1/3 by the rest of the term beca=
use
> 1/2 and 1/3 are scalars, and * and .* do the same thing when one of their
> inputs are scalar.
>
> --
> Steve Lord
> sl...@mathworks.com- =E9=9A=90=E8=97=8F=E8=A2=AB=E5=BC=95=E7=94=A8=E6=96=
=87=E5=AD=97 -
>
> - =E6=98=BE=E7=A4=BA=E5=BC=95=E7=94=A8=E7=9A=84=E6=96=87=E5=AD=97 -

Thank you for your answer. Now I have managed to solve my problem. And
I do use '.*' and '.^' for vector calculation. But I gave up my
original thoughts about define 'sym' variable.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us