In [1]:
%pylab inline
from mba import *
seed(13)
In [2]:
def foo(c):
return sin(c[0]/100) + sin(c[1]*3)
cmin = [0.0, 0.0]
cmax = [1000.0, 10.0]
C = mgrid[0:cmax[0]:1e-1,0:cmax[1]:1e-1]
F = foo(C)
coo = uniform(cmin, cmax, (128,2))
val = foo(coo.transpose())
figure(figsize=(13,4))
pcolormesh(C[0], C[1], F)
scatter(coo[:,0], coo[:,1], c='k', s=1)
xlim([cmin[0], cmax[0]])
ylim([cmin[1], cmax[1]])
tight_layout()
Size of the target grid:
In [3]:
C.shape[1:]
Out[3]:
In [4]:
ny = 16
for nx in (16, 8, 4):
interp = mba2(cmin, cmax, [nx,ny], coo, val)
error = amax(abs(val - interp(coo))) / amax(abs(val))
print(interp)
G = interp(C.transpose((1,2,0)).copy())
figure(figsize=(12,4))
pcolormesh(C[0], C[1], G)
scatter(coo[:,0], coo[:,1], c='k', s=1)
xlim([cmin[0], cmax[0]])
ylim([cmin[1], cmax[1]])
title(f'$n_0=[{nx},{ny}], \\quad \\varepsilon={error:e}$')
tight_layout()
In [5]:
nx = 16
for ny in (16, 32, 64):
interp = mba2(cmin, cmax, [nx,ny], coo, val)
error = amax(abs(val - interp(coo))) / amax(abs(val))
print(interp)
G = interp(C.transpose((1,2,0)).copy())
figure(figsize=(12,4))
pcolormesh(C[0], C[1], G)
scatter(coo[:,0], coo[:,1], c='k', s=1)
xlim([cmin[0], cmax[0]])
ylim([cmin[1], cmax[1]])
title(f'$n_0=[{nx},{ny}], \\quad \\varepsilon={error:e}$')
tight_layout()