In [1]:
import numpy as np
In [42]:
x = np.linspace(1,8,5)
In [43]:
x.shape
Out[43]:
In [44]:
y = np.sin(x)
In [45]:
y.shape
Out[45]:
In [46]:
for i in range(y.shape[0]-1):
print( (y[i+1]-y[i]),(y[i+1]-y[i])/(x[i+1]-x[i]))
In [47]:
y[1:]-y[:-1]
Out[47]:
In [48]:
y[1:]
Out[48]:
In [ ]:
In [ ]:
(y[1:]-y[:-1])/(x[1:]-x[:-1])
In [ ]:
np.diff(y)
In [50]:
np.diff(x)
Out[50]:
In [31]:
np.roll(y,-1)
Out[31]:
In [30]:
y
Out[30]:
In [32]:
np.gradient(y)
Out[32]:
In [66]:
import sympy
In [67]:
X = sympy.Symbol('X')
In [68]:
expr = (sympy.sin(X**2+1*sympy.cos(sympy.exp(X)))).diff(X)
In [73]:
expr
Out[73]:
In [71]:
f = sympy.lambdify(X,expr,"numpy")
In [72]:
f( np.array([1,2,3]))
Out[72]:
In [77]:
import ipywidgets as widgets
from ipywidgets import interact
In [79]:
widgets.IntSlider?
In [82]:
@interact(x=widgets.IntSlider(1,2,10,1))
def g(x=1):
print(x)
In [68]:
import numpy as np
N = 10
x = np.linspace( 0,np.pi*1.23, N)
In [69]:
f = np.sin(x)
In [70]:
x,f
Out[70]:
In [71]:
np.diff(x)
Out[71]:
In [72]:
np.sum(f[:-1]*np.diff(x))
Out[72]:
In [73]:
w = np.ones_like(x)
h = np.diff(x)[0]
In [74]:
w[-1] = 0
In [75]:
h*np.sum(w*f)
Out[75]:
In [76]:
w[0] = 0.5
w[-1] = 0.5
h*np.sum(w*f)
Out[76]:
In [77]:
import scipy.integrate
In [78]:
scipy.integrate.
In [ ]:
In [79]:
np.cumsum(f)*h
Out[79]:
In [80]:
np.sum(f)*h
Out[80]:
In [82]:
f.shape,np.cumsum(f).shape
Out[82]:
In [101]:
x = np.linspace(0,2,50)
y = np.linspace(0,2,50)
In [102]:
X,Y = np.meshgrid(x,y,indexing='xy')
In [103]:
X
Out[103]:
In [104]:
F = np.sin(X**2 + Y)
In [105]:
F[1,2],X[1,2],Y[1,2]
Out[105]:
In [106]:
%matplotlib inline
import matplotlib.pyplot as plt
In [108]:
plt.contour(X,Y,F)
Out[108]:
In [110]:
plt.imshow(F,origin='lower')
Out[110]:
In [117]:
np.diff(F,axis=1).shape
Out[117]:
In [118]:
np.diff(F,2,axis=0).shape
Out[118]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: