Ask Your Question
1

Absolute value of complex numbers in 3D plot

asked 2014-07-22 23:43:09 +0200

Rongcui Dong gravatar image

updated 2014-07-23 00:45:06 +0200

When I try to make a 3d plot with complex numbers in it, such as this one:

plot3d(1+x+abs(i*omega), (x,0,5), (omega,0,5), viewer='tachyon')

I get errors saying

TypeError: unable to coerce to a real number

On another one I got

TypeError: Unable to convert 0.0345000000000000*I to float

Why is this happening?


EDIT: Thanks for slelievre, lambda makes minimal example work. However, the original problem (I wanted to plot frequency responses) gives another error. Here is the original problem:

G_do_ideal_qn = -31.6656111462951*(0.0345000000000000*I*omega - 359.196869250000)/(-0.000389160000000000*omega^2 + 1.03531167486000*I*omega + 180.342274500000)

Tried to plot with

plot3d(lambda omega, V_C: 20*log(abs(G_do_ideal_qn), 10), (omega, 10, 100e3), (V_C, 0, 400))

Gives error

TypeError: unable to simplify to float approximation
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-07-22 23:53:09 +0200

slelievre gravatar image

updated 2014-07-23 05:42:49 +0200

(In your example, you could just replace abs(i*omega) by abs(omega), but I'm sure you gave a simpler example than the examples you really care about.)

It often helps to use a lambda function for plots, as in:

plot3d(lambda x, omega: 1+x+abs(i*omega), (x,0,5), (omega,0,5), viewer='tachyon')

I think the explanation is that functions applied to symbolic expressions often misbehave, while the lambda trick makes sure the functions only get applied to numerical input for plotting.


EDIT: In the new problem described in your edit, you ask for a 3d plot of a function of omega and V_C, but this function depends only on omega, and not at all on V_C, so a 2d plot would suffice. But maybe that's again just because you used a simplified version of your input, for the sake of the question.

One way to make things work is to make 'G_do_ideal_qn' a function rather than just an expression. Below I'm shortening a tiny bit the names and the values just to make things fit on one line.

sage: G_do(om,V) = -31.*(0.03*I*om - 359.)/(-0.0003*om^2 + 1.03*I*om + 180.)
sage: plot3d(lambda om, V: 20*log(abs(G_do(om,V)), 10), (om, 10, 100e3), (V, 0, 400))
edit flag offensive delete link more

Comments

OK, the minimal example works... Then I moved forward to approach the original problem (I wanted to plot frequency response) with 1+x+log(abs(i*omega), 10) and another error came up. I will update on original question.

Rongcui Dong gravatar imageRongcui Dong ( 2014-07-23 00:37:23 +0200 )edit

I edited my answer to address your updated question.

slelievre gravatar imageslelievre ( 2014-07-23 05:58:36 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-07-22 23:43:09 +0200

Seen: 996 times

Last updated: Jul 23 '14