Well I did use your method but I still get an error.

Code:

r,z = var('r,z')

gro = 1.0
kro = 3.0

def f(r,z): term1 = (1+(bessel_J(0, gro)/bessel_J(2,gro)))*(r/
kro)*(bessel_J(1, r)/bessel_J(1,gro))*cos(z) term2 = -(bessel_J(0,r)/
bessel_J(2, gro))*(r**2/kro**2) return term1 + term2 if t != 0 else
infinity

p = contour_plot(f , (r, 0, 2.5), (z, 0, 4), axes_labels=['$r$','$z
$'], contours = [0.0, 0.2, 0.4, 0.6, 0.8], labels = True, label_inline
= True, label_colors = 'black', label_inline_spacing = 0.01,
fill=False, aspect_ratio=1, legend_label='Polodial')

show(p)

Error:

File "", line 1, in <module>

  File "/tmp/tmpra5Mm9/___code___.py", line 8
    def f(r,z): term1 = (_sage_const_1 +(bessel_J(_sage_const_0 , gro)/
bessel_J(_sage_const_2 ,gro)))*(r/kro)*(bessel_J(_sage_const_1 , r)/
bessel_J(_sage_const_1 ,gro))*cos(z) term2 = -
(bessel_J(_sage_const_0 ,r)/bessel_J(_sage_const_2 ,
gro))*(r**_sage_const_2 /kro**_sage_const_2 ) return term1 + term2 if
t != _sage_const_0  else infinity
 
^
SyntaxError: invalid syntax

Some sort of syntax error.

Also if I have the terms, and return on separate lines in the
definition then I get this error. Where the system still believes
there is a t term floating around.

Error:

term1 = (1+(bessel_J(0, gro)/bessel_J(2,gro)))*(r/kro)*(bessel_J(1, r)/
bessel_J(1,gro))*cos(z)
  File "", line 1, in <module>

  File "/tmp/tmp31dCf5/___code___.py", line 13, in <module>
    p = contour_plot(f , (r, _sage_const_0 , _sage_const_2p5 ), (z,
_sage_const_0 , _sage_const_4 ), axes_labels=['$r$','$z$'], contours =
[_sage_const_0p0 , _sage_const_0p2 , _sage_const_0p4 ,
_sage_const_0p6 , _sage_const_0p8 ], labels = True, label_inline =
True, label_colors = 'black', label_inline_spacing =
_sage_const_0p01 , fill=False, aspect_ratio=_sage_const_1 ,
legend_label='Polodial')
  File "/sagenb/sage_install/sage-4.7/local/lib/python2.6/site-
packages/sage/misc/decorators.py", line 381, in wrapper
    return func(*args, **kwds)
  File "/sagenb/sage_install/sage-4.7/local/lib/python2.6/site-
packages/sage/misc/decorators.py", line 381, in wrapper
    return func(*args, **kwds)
  File "/sagenb/sage_install/sage-4.7/local/lib/python2.6/site-
packages/sage/misc/decorators.py", line 432, in wrapper
    return func(*args, **options)
  File "/sagenb/sage_install/sage-4.7/local/lib/python2.6/site-
packages/sage/plot/contour_plot.py", line 475, in contour_plot
    for y in xsrange(*ranges[1], include_endpoint=True)]
  File "/tmp/tmp31dCf5/___code___.py", line 11, in f
    return term1 + term2 if t != _sage_const_0  else infinity
NameError: global name 't' is not defined

On Oct 20, 8:38 pm, "D. S. McNeil" <dsm...@gmail.com> wrote:
> > def f(y,t): return (1+(bessel_J(0, gro)/bessel_J(2, gro)))*(r/
> > kro)*(bessel_J(1, r)/bessel_J(1,gro))*z.cos()-(bessel_J(0,r)/
> > bessel_J(2, gro))*(r**2/kro**2) if t != 0 else infinity
>
> A few things:
>
> (1) Your arguments to this function are y and t, but inside you use r
> and z.  r and z are still the symbolic values.  That's why the error
> message says "Cannot evaluate symbolic expression to a numeric value",
> and that's usually the problem: some variable isn't being assigned a
> number.
>
> (2) Since z is going to be a float, not a Sage real, "z.cos()" isn't
> going to work as .cos() isn't a float method.  (Sorry about this; in a
> sense it's an implementation detail there's no way to guess.  Python
> floats are low-level "dumb" numbers which only have a few methods
> living inside them.)
>
> (3) The "if condition else infinity" trick was a workaround for a
> singularity that wasn't being handled too well.  If there isn't one,
> there's no need to worry about it.
>
> So I'd simply replace your f function with something like
>
> def f(r,z):
>     term1 = (1+(bessel_J(0, gro)/bessel_J(2,
> gro)))*(r/kro)*(bessel_J(1, r)/bessel_J(1,gro))*cos(z)
>     term2 = -(bessel_J(0,r)/bessel_J(2, gro))*(r**2/kro**2)
>     return term1 + term2
>
> [possible typos, I didn't check too carefully, but you get the idea]
>
> Doug

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to