ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 22 Mar 2012 03:53:15 +0100min(x,y)=x ... and then plot3d f(x,y)=min(x,y)https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/ 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 :) )
Wed, 21 Mar 2012 16:05:43 +0100https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/Answer by kcrisman for <p>Hi all</p>
<p>I can understand the following somewhat surprising result :</p>
<pre><code>sage: var('x,y')
(x, y)
sage: min(x,y)
x
</code></pre>
<p>A friend of mine wants to plot3d the function that a human should write
f(x,y)=min(|x|,|y|)</p>
<p>what she does is</p>
<pre><code>sage: f(x,y)=min(abs(x),abs(y))
sage: plot3d(f,(x,-2,2),(y,-2,2))
</code></pre>
<p>of course, it does not produce the expected result because of what I said in introduction about min(x,y). By the way :</p>
<pre><code>sage: f(4,1)
4
</code></pre>
<p>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).</p>
<p>The following works :</p>
<pre><code>sage: f=lambda x,y:min(abs(x),abs(y))
</code></pre>
<p>I guess that </p>
<pre><code>def f(x,y):
return min(abs(x),abs(y))
</code></pre>
<p>will also work.</p>
<p>So my questions are :</p>
<ol>
<li>why min(x,y)=x ?</li>
<li>how can I "predict" if such or such function will not work using the simple declaration f(x,y)=blahblah ?</li>
<li>what is the best way to deal with such cases ?</li>
</ol>
<p>Thanks for any help</p>
<p>have a good night</p>
<p>Laurent Claessens (on the night timezone :) )</p>
https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/?answer=13383#post-id-13383I can't find this, but I'm pretty sure there is another question with this on ask.sagemath.org.
sage: var('y')
y
sage: min(x,y)
x
sage: min_symbolic(x,y)
min(x, y)
I think if you use the latter, all should be well. I hope? Don't have time to try now. Good luck!
Wed, 21 Mar 2012 16:28:20 +0100https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/?answer=13383#post-id-13383Comment by Laurent Claessens for <p>I can't find this, but I'm pretty sure there is another question with this on <a href="http://ask.sagemath.org">ask.sagemath.org</a>.</p>
<pre><code>sage: var('y')
y
sage: min(x,y)
x
sage: min_symbolic(x,y)
min(x, y)
</code></pre>
<p>I think if you use the latter, all should be well. I hope? Don't have time to try now. Good luck!</p>
https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/?comment=20090#post-id-20090Yes, `min_symbolic` is the answer. Thanks :)Thu, 22 Mar 2012 03:53:15 +0100https://ask.sagemath.org/question/8809/minxyx-and-then-plot3d-fxyminxy/?comment=20090#post-id-20090