In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
x = np.linspace(0,7,10)
x
Out[2]:
In [3]:
f = np.sin(x)
In [5]:
plt.plot(x,f)
Out[5]:
In [8]:
for i in xrange(x.shape[0]-1):
#print f[i], f[i+1]
if f[i]*f[i+1]<=0:
#print x[i], x[i+1]
a=(f[i+1]-f[i])/(x[i+1]-x[i])
b=f[i]-a*x[i]
x_0=-b/a
print x_0
$$F(x) = \int_c^x f(x')dx'$$
In [9]:
timeit('np.zeros(1000000,dtype=np.float64)')
In [10]:
a = np.empty(1000000,dtype=np.float64)
In [11]:
timeit('a.fill(0.0)')
Maximum
In [12]:
np.max(f)
Out[12]:
In [13]:
f[np.argmax(f)]
Out[13]:
In [14]:
x[np.argmax(f)]
Out[14]:
In [15]:
x[np.argmin(f)]
Out[15]:
array slicing
In [16]:
x[1:4]
Out[16]:
In [17]:
x[1:6:2]
Out[17]:
In [18]:
x[::2]
Out[18]:
In [19]:
x[:-1],x[-1]
Out[19]:
In [20]:
x.shape
Out[20]:
In [21]:
x[1:].shape
Out[21]:
In [22]:
x[:-1].shape
Out[22]:
In [34]:
x = np.linspace(0,7,10)
f = np.sin(x)
In [35]:
h = x[1]-x[0]
fdiff = (f[1:]-f[:-1])/h
In [36]:
fdiff.shape, (x[:-1]+x[1:]).shape
Out[36]:
In [38]:
y = np.linspace(0,7,230)
plt.plot((x[:-1]+x[1:])/2.0,fdiff, 'o-')
plt.plot( y,np.cos(y))
Out[38]:
In [39]:
f[1:]-f[:-1]
Out[39]:
In [40]:
np.diff(f)
Out[40]:
całka
In [41]:
h = x[1]-x[0]
w = h*np.ones_like(f)
w[0] = w[0]/2.0
w[-1] = w[-1]/2.0
np.sum(f*w)
Out[41]:
In [43]:
# sage integrate(sin(y),(y,0,7)).n()
In [46]:
x = np.linspace(0,7,41)
h = x[1]-x[0]
f = np.sin(x)
plt.plot(x,np.cumsum(f*h))
plt.plot(y,-np.cos(y)+1)
Out[46]:
In [33]:
Out[33]: