Find an Inverse for the Exponential Integral function

1.3k views Asked by At

I have a program where I have to find x. But I have to use the special function Ei - the exponential integral, and x is inside the argument of Ei. So Python isn't recognizing it.

ei(mx) = te^r + ei(c)

Here the RHS is a constant alongwith m. I want to find the value of x, and then append it to a list. But Python isn't able to do this.

from scipy import special
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

Y = []
X = np.arange(0,10,.1)
for i in X:
    y = scipy.special.expi(i)
    Y.append(y)

N_0 = 2
t_f = 100
r = 2
K = 100
N_t = [N_0,]
t = np.arange(0,100,1)
for i in t:
    l = i*e**r + scipy.special.expi(r*N_t[i]/K)
    N_t.append(l)
plt.plot(X,Y)
plt.plot(t,N_t)
plt.show
1

There are 1 answers

0
Bill Bell On BEST ANSWER

I've corrected some mistakes in your code to give the following. You should compare this with your code line by line.

from scipy.special import expi
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

Y = []
X = np.arange(0,10,.1)
for i in X:
    y = expi(i)
    Y.append(y)

N_0 = 2
t_f = 100
r = 2
K = 100
N_t = [N_0,]
t = np.arange(0,100,1)
for i in t:
    l = i*np.exp(r) + expi(r*N_t[i]/K)
    N_t.append(l)
plt.plot(X,Y)
plt.plot(t,N_t)
plt.show()

However, there is still one possible flaw that I notice and can't resolve. You plot X and t together in the same graph at the end yet X ranges over 0 to 10 and t ranges over 0 to 100. Is this what you intended?

Also matplotlib complains that the lengths of the vectors supplied to it in the second call to plot are not the same.