I'm trying to write a simple program to plot x vs y. However, it does not seem to be computing the correct value ofy.
For instance in the first case when x = -1 the value of e^(x^2/2 - x) -1 should be 3.48, but instead it is returning 1.
The other error I have is it doesn't seem to be plotting x vs y, but instead a separate line for each value of x.
import numpy as np
import math
import matplotlib.pyplot as plt
x = np.arange(-2, 2)
y = np.arange(-2, 2)
for i in range(-3, 3):
y[i] = math.exp(( x[i]^2/2 ) - x[i])-1
print x, y
plt.plot([x, y])
plt.show()
**, not^; (2)xis an integer array, sox[i]**2/2uses integer arithmetic in Python 2. You can fix that by usingx[i]**2/2.0.