On Wed, Jun 10, 2009 at 9:53 AM, evlu...@gmail.com<evlu...@gmail.com> wrote:
> I get this error:
>
> Traceback (most recent call last):
> ,,,
> TypeError: float() argument must be a string or a number
>
> I guess that sage is trying to evaluate the integral before
> substituting the value for b. Is this correct? How can I get around
> this?

The issue is that you have is that when you do u(x,b), it does s(x)
which doesn't work since s requires a specific numeric value.

I've posted some code which works and is much faster.  Changes to note are

1) Use of "i = CDF.gen()" since we are going to be doing things
numerically, this is a bit more efficient.

2) The line "zz = fast_callable(zprime(x)/(z(x)-b), vars=[x,b])" which
makes an object which can quickly evaluate that expression.  This is
useful since the numerical integral has to evaluate the function at a
lot of points.

3) Using exp instead of e^ since exp() will try to call the exp()
method directly on its argument.

4) The "lambda x:" in the numerical integral which prevents the error
you were seeing above since x will always be a specific value when
passed into s.

5) The [0] after the numerical integral since that returns a (value,
error) tuple.

sage: f(0)
0.207543207489 - 0.30709310513*I
sage: %timeit f(0)
10 loops, best of 3: 23.4 ms per loop

--Mike

theta_array = [(0,0),(1,2),(pi/2,pi),(pi,4),(3*pi/2,5),(2*pi,2*pi)]
s = spline(theta_array)
i = CDF.gen()
ellipse(x) = e^(i*x)-1/2*e^(-i*x)
z(t) = ellipse(t)
zprime(t) = derivative(z)

b = var('b')
zz = fast_callable(zprime(x)/(z(x)-b), vars=[x,b])

def w(x, b):
   return zz(x,b)*exp(i*s(x))

def f(b):
    res = 1/(2*pi*i)*(integral_numerical(lambda x:
w(x,b).real(),0,2*pi)[0] + i * integral_numerical(lambda x:
w(x,b).imag(),0,2*pi)[0])
    return res.n()

--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to