ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 26 Sep 2014 07:39:08 -0500What am I doing wrong with this functionhttp://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/ I want to plot a function and its inverse.
I issue
F=plot ((2*(x^3-2)),-4,0)
G=plot(sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3),-4,0)
F+G
Now 2(x^3-2) is the inverse of (0.5x+2)^(1/3) (I even checked with a well known alternative to sage).
The plots come out with the scale of 2(x^3-2) all wrong. They should (obviously) be reflections in y=x.
Any help much appreciated
Fri, 26 Sep 2014 05:54:31 -0500http://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/Answer by tmonteil for <p>I want to plot a function and its inverse.
I issue</p>
<pre><code>F=plot ((2*(x^3-2)),-4,0)
G=plot(sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3),-4,0)
F+G
</code></pre>
<p>Now 2(x^3-2) is the inverse of (0.5x+2)^(1/3) (I even checked with a well known alternative to sage).</p>
<p>The plots come out with the scale of 2(x^3-2) all wrong. They should (obviously) be reflections in y=x.</p>
<p>Any help much appreciated</p>
http://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/?answer=24303#post-id-24303Let me denote ``2*(x^3-2)`` by ``f`` and ``sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3)`` by ``g``.
Since ``f`` and ``g`` are inverse to each other (on the whole real line), there is a symmetry of the whole graphs with respect to the line {x=y}, but you do not see it.
First, you need to have the same scale for x and y axes, you can get this by setting the option ``aspect_ratio=1``.
Second, you look at the interval [-4,0] for both functions while this interval is not invariant: ``f([-4,0])`` is not equal to ``[-4,0]``, so the graph of ``g`` on ``[-4,0]`` has no reason to be symmetric of the graph of ``f`` on ``[-4,0]``. If you want to see the symmetry, you need to plot the graph of ``g`` on the image of ``[-4,0]`` by ``f``.
sage: f = 2*(x^3-2)
sage: g = sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3)
sage: f(-4)
-132
sage: f(0)
-4
sage: F = plot ((2*(x^3-2)),-4,0, aspect_ratio=1)
sage: G = plot(sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3),-132,-4, aspect_ratio=1)
sage: F+G
So, you can see that ``f:[-4,0] -> [-132,-4]`` is a bijection whose inverse is ``g: [-132,-4] -> [-4,0]``.
The plot is even nicer for the map ``f:[-3,3] -> [-58,50]``:
sage: f(-3)
-58
sage: f(3)
50
sage: F = plot ((2*(x^3-2)),-3,3, aspect_ratio=1)
sage: G = plot(sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3),-58,50, aspect_ratio=1)
sage: F+G
Conclusion : maps are not only formulas, but require domain and codomain to be well defined !
Fri, 26 Sep 2014 07:39:08 -0500http://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/?answer=24303#post-id-24303Answer by nerak99 for <p>I want to plot a function and its inverse.
I issue</p>
<pre><code>F=plot ((2*(x^3-2)),-4,0)
G=plot(sign(0.5*x+2.0)*abs(0.5*x+2.0)^(1/3),-4,0)
F+G
</code></pre>
<p>Now 2(x^3-2) is the inverse of (0.5x+2)^(1/3) (I even checked with a well known alternative to sage).</p>
<p>The plots come out with the scale of 2(x^3-2) all wrong. They should (obviously) be reflections in y=x.</p>
<p>Any help much appreciated</p>
http://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/?answer=24297#post-id-24297Duh, I haver to restrict the range on the first function. Sorry Fri, 26 Sep 2014 06:03:32 -0500http://ask.sagemath.org/question/24296/what-am-i-doing-wrong-with-this-function/?answer=24297#post-id-24297