# 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

edit retag close merge delete

Sort by » oldest newest most voted

Duh, I haver to restrict the range on the first function. Sorry

more

Let 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 !

more