In [19]:
import numpy as np
from scipy.integrate import trapz
from matplotlib import pylab as plt
%matplotlib inline
In [20]:
def grid_vect(a,b,N):
x = np.linspace(a, b, N, endpoint=True)
h = x[1] - x[0]
return np.mgrid[a:b+h:h, a:b+h:h].reshape(2,-1).T
def get_meshgrid(a,b,N):
x = np.linspace(a, b, N, endpoint=True)
return np.meshgrid(x,x)
def f(x):
return x[0]+2*x[1]
xy = grid_vect(0,1,5)
#print(xy)
#fig = plt.figure(figsize=(10,5))
#plt.grid(True)
#plt.scatter(xy[:,0],xy[:,1], marker='x', color = 'r', s = 50)
In [21]:
xg,yg = get_meshgrid(0,1,5)
#fig = plt.figure(figsize=(10,5))
#plt.grid(True)
#plt.scatter(xg,yg, marker='x', color = 'r', s = 50)
In [23]:
from mpl_toolkits.mplot3d.axes3d import Axes3D
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
p = ax.plot_surface(xg, yg, f([xg,yg]), rstride=4, cstride=4, linewidth=0)
In [24]:
np.trapz(np.trapz(f([xg,yg]),xg), yg[:,0])
Out[24]:
In [6]:
np.trapz(f(xg,yg)[1],xg[1])
Out[6]:
In [7]:
np.trapz(f(xg,yg),xg)
Out[7]:
In [18]:
xg.shape
Out[18]:
In [9]:
yg[:,0]
Out[9]:
In [12]:
f(xg,yg)
Out[12]:
In [13]:
xg[1]
Out[13]:
In [15]:
f(xg,yg)[1]
Out[15]:
In [17]:
xy.shape
Out[17]: