Plotting long functions

28 views
Skip to first unread message

Fjordforsk A/S

unread,
Dec 28, 2016, 7:19:55 AM12/28/16
to sage-support
Hello, I am not sure on the reply sage gives me on plotting a long function:

sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(x)), (x, -2, 2), (t, -2, 2)


TypeError: plot3d() takes at least 3 arguments (1 given)

I have defined x and t as variables, should I define e as well?

Thanks!

Michael Orlitzky

unread,
Dec 28, 2016, 8:47:50 AM12/28/16
to sage-s...@googlegroups.com
I think you just made a typo in there somewhere. The function part of
your example doesn't parse as a function; I get a syntax error if I do f
= <all that stuff>.

Fjordforsk A/S

unread,
Dec 28, 2016, 10:33:05 AM12/28/16
to sage-support
This is how its supposed to go:

sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) + i*x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 + 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(i*x)), (x, -2, 2), (t, -2, 2)


However, Sage thinks that 3*t^2 = Integer(3)*t**Integer(2)

That is , twice multiplied with 2, and not exponent to two.

How should I otherwise write this function?



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-46-c5f2adcd43ea> in <module>()
----> 1 plot3d(((Integer(1) - (Integer(3)/Integer(8) - Integer(3)*t**Integer(2) - Integer(2)*t**Integer(4) - Integer(9)*x**Integer(2) - Integer(10)*x**Integer(4) - Integer(12)*t**Integer(2)*x**Integer(2)) + i*x*(Integer(15)/Integer(4) + Integer(6)*t**Integer(2) - Integer(4)*t**Integer(2) - Integer(2)*x**Integer(2) - Integer(4)*x**Integer(4) + Integer(8)*t**Integer(2)*x**Integer(2)))/(Integer(1)/Integer(8)*(Integer(3)/Integer(4) + Integer(9)*t**Integer(2) + Integer(4)*t**Integer(2)+ Integer(16)/Integer(3)*t**Integer(6) + Integer(33)*x**Integer(2) + Integer(36)*x**Integer(24) + Integer(16)/Integer(3)*x**Integer(6))))*e**(i*x)), (x, -Integer(2), Integer(2)), (t, -Integer(2), Integer(2))


TypeError: plot3d() takes at least 3 arguments (1 given)
sage:

Michael Orlitzky

unread,
Dec 28, 2016, 10:58:00 AM12/28/16
to sage-s...@googlegroups.com
On 12/28/2016 10:33 AM, Fjordforsk A/S wrote:
> This is how its supposed to go:
>
> sage: plot3d(((1 - (3/8 - 3*t^2 - 2*t^4 - 9*x^2 - 10*x^4 - 12*t^2*x^2) +
> i*x*(15/4 + 6*t^2 - 4*t^2 - 2*x^2 - 4*x^4 + 8*t^2*x^2))/(1/8*(3/4 + 9*t^2 +
> 4*t^2+ 16/3*t^6 + 33*x^2 + 36*x^24 + 16/3*x^6)))*e^(i*x)), (x, -2, 2), (t,
> -2, 2)
>
>
> However, Sage thinks that 3*t^2 = Integer(3)*t****Integer(2)
>
> That is , twice multiplied with 2, and not exponent to two.

The double-star means exponentiation in both python and in sage:

sage: 2^8
256
sage: 2**8
256

But beware, the carat "^" has a special meaning in sage. In python, it
does something else entirely:

>>> 2^8
10

In any case, your problem is elsewhere... I think you've got an extra
parenthesis at the end of your expression. Instead of "e^(i*x))", you
should have "e^(i*x)". Then you'll need another parenthesis at the end
of the whole thing.

After that, well, at least you get a different error =)

It crashes for me because it's trying to plot a point with a non-zero
imaginary part. It could be that the imaginary part is tiny -- in which
case you can throw it away -- or else you might have to rearrange your
expression, or break up the domain.

Fjordforsk A/S

unread,
Dec 29, 2016, 4:46:10 AM12/29/16
to sage-support
Thanks Michael. I am plotting it now, and it is just waiting without giving a crash.
Is it automatically right to use complex_plot command to plot the imaginary part of the same plot as given below?

Michael Orlitzky

unread,
Dec 29, 2016, 10:28:43 AM12/29/16
to sage-s...@googlegroups.com
On 12/29/2016 04:46 AM, Fjordforsk A/S wrote:
> Thanks Michael. I am plotting it now, and it is just waiting without giving
> a crash.
> Is it automatically right to use complex_plot command to plot the imaginary
> part of the same plot as given below?
>

It depends, do you expect your function to take on complex values? When
plotting, sage is forced to evaluate your expression numerically at a
number of points. That isn't 100% accurate, and you can wind up with a
situation where expression1 == expression2, but numerically evaluating
(expression1 - expression2) gives you e.g. 0.00000000000134*i.

In cases like that, you want to throw away the imaginary part, because
your function isn't actually imaginary. If you were to use complex_plot
on something like that, the result would only mislead you.


Reply all
Reply to author
Forward
0 new messages