Ask Your Question

Revision history [back]

min(x,y)=x ... and then plot3d f(x,y)=min(x,y)

Hi all

I can understand the following somewhat surprising result :

sage: var('x,y')
(x, y)
sage: min(x,y)
x

A friend of mine wants to plot3d the function that a human should write f(x,y)=min(|x|,|y|)

what she does is

sage: f(x,y)=min(abs(x),abs(y))
sage: plot3d(f,(x,-2,2),(y,-2,2))

of course, it does not produce the expected result because of what I said in introduction about min(x,y). By the way :

sage: f(4,1)  
4

So ... well ... what do I have to say to her ? What is the best way to plot a function (in the math sense of the term) when it cannot be managed by a function (in the Sage sense of the term).

The following works :

sage: f=lambda x,y:min(abs(x),abs(y))

I guess that

def f(x,y):
   return min(abs(x),abs(y))

will also work.

So my questions are :

  1. why min(x,y)=x ?
  2. how can I "predict" if such or such function will not work using the simple declaration f(x,y)=blahblah ?
  3. what is the best way to deal with such cases ?

Thanks for any help

have a good night

Laurent Claessens (on the night timezone :) )