I am working with a double integral, and the inner integral has variable bounds. I wrote a function, using SciPy's quad integration, that allows me to evaluate this integral. However, what I want is to just evaluate the inner integral, so that all I am left with is a single, non-evaluated integral with respect to some variable. I want to then plot this "half-way" evaluated double integral vs. a range of that variable so that I can see some trend. However, when I input an array of that variable (it is just 0-10000 but increments of 1, it provides the following error message:
"ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
I have defined functions before that allow me to input an array (which outputs that function at however many points were in the array), so I am unsure as to why this message is popping up now. I think it has something to do with me using SciPy's "quad" integration when defining the function. How do I go around this so that I can input an array?
import numpy as np
from scipy import integrate
from scipy.integrate import quad
import matplotlib.pyplot as plt
#This is the array of values of the variable I ultimately want to have the function plotted
against
timearray = np.arange(0,10000,1)
#This below defines the general function, that is with respect to two variables (p and t)
def thomtest(p,t):
d = 3.086e22
c = 2.998e10
return (3*((np.cos(p + (2*t/(d*p))))**2))/(8*(t+((p**2)*d/(2*c))))
#The function below evaluates just the inner-integral
def phib(t):
d = 3.086e22
c = 2.998e10
return quad(thomtest,0.00001*(c*t)/d,np.pi, args=(t))[0]
#This evaluates the outer-integral, giving me the complete numerical answer
doubleintegral = quad(phib,0,((3.086e22)/(2.998e10)))
#This below is what gives me the error message: "ValueError: The truth
#value of an array with more than one element is ambiguous.
#Use a.any() or a.all()". Apparently I cannot input an array
print(phib(timearray))