0

I used scipy.integrate to get the value of the Fresnel integrals, and I now wish to plot the Cornu spiral. However, when I attempt to create an array with the value of the integral for multiple inputs, I get the error mentioned in the title. I can't see how what I'm doing has anything to do with the Truth value mentioned in the error.

My code:

def COSINTEGRAND(x):
    return math.cos((pi * x**2)/2)
def SININTEGRAND(x):
    return math.sin((pi * x**2)/2)
def COSINTEGRAL(u):
    return quad(COSINTEGRAND, 0, u)
def SININTEGRAL(u):
    return quad(SININTEGRAND, 0, u)

a = np.linspace(-10,10,100)
b = COSINTEGRAL(a)
print (b)

Any explanation of the error or methods to fix this would be appreciated. I got the same error when trying to plot the spiral directly- it appears to refer to a part of the scipy.integrate code

1
  • What is the dtype of the arrays here? are these numpy arrays? if so call np.cos etc Commented Mar 4, 2016 at 13:23

2 Answers 2

2

Many of the functions you're using don't know how to handle numpy arrays. This includes the scipy.integrate.quad function.

quad docs: http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html#scipy.integrate.quad

Sign up to request clarification or add additional context in comments.

3 Comments

That doesn't appear to have made a difference, unfortunately. I get an identical error when replacing math.cos and math.sin with np.cos and np.sin
scipy.integrate.quad's third argument (u in your COSINTEGRAL) also takes a regular float, rather than a numpy array.
Ok, thanks. Does this mean that for me to plot the value over multiple inputs, I would have to write a loop to run the function multiple times?
0

In this particular case, you can use Fresnel integeals as implemented in http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.special.fresnel.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.