# How to plot correctly these two simple exponential functions? This post is a wiki. Anyone with karma >750 is welcome to improve it.

Im trying to plot this function $f=x^{1/x}$ with this code:

x = var('x')

f = x^(1/x)

show(f)

plot(f,x,-5,5)

but SAGE says that 'negative number cannot be raised to a fractional power'??? This make no sense to me, SAGE cant do this easy task? Really??

Because I dont believe it at all I tried to check the same with the function $g=2^{1/x}$

This time dont shows any error but the plot was completely wrong. If some one can help me I will appreciate it a lot. Yes, I tried to find the solution on the documentation but I dont encountered anything so helpful. Thank you in advance.

edit retag close merge delete

1

Sort by » oldest newest most voted Hi,

sage is correct saying that a negative number cannot be raised to a fractional power IF you want to plot it. For example

f(-2)=-1/2*sqrt(-2)
f(2)=sqrt(2)


The first one is imaginary, the other one real, so you cannot plot both in the same 2D plot. You could use the abs() function to avoid this problem. Another thing is

sage: f(x).limit(x=0,dir='+')
0
sage: f(x).limit(x=0,dir='-')
+Infinity


so that your plot for either f or g will have a huge peak which will suppress the rest of the plot. Try the following:

sage: f1(x)=x^(1/x)
sage: f2(x)=(-x)^(1/x)
sage: p1=plot(f1(x),0,5)
sage: p2=plot(f2(x),-5,-0.5)
sage: show(p1+p2)

more

I want to plot the imaginary part, how I can do it then? I search for something similar to Re or Im functions but I not encountered. And thank you very much for the info.

Try imag, imag_part or imaginary, they should do the trick. And remember to use help or ? often to find out what a function does.