-2

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
Adeetya
  • 101
  • 9
  • 2
    So what does your actual code look like? –  Dec 16 '16 at 12:18
  • Are you even using Scipy? [expi](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.expi.html#scipy.special.expi) sounds exactly like what you are looking for – UnholySheep Dec 16 '16 at 12:19
  • I am. But scipy function ei is not able to calculate a variable inside the argument of the function. It can easily calculate ei for constant values, but not find e(x) = C. – Adeetya Dec 16 '16 at 12:25
  • 1
    You can't do `e(x) = C` on paper either - you need to solve this equation for `x` first (or use some specialized software/library for solving equations) – UnholySheep Dec 16 '16 at 12:35
  • 1
    @UnholySheep Scipy has a collection of root finding functions. – Gribouillis Dec 16 '16 at 12:44

1 Answers1

1

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.

Bill Bell
  • 21,021
  • 5
  • 43
  • 58