2 DInterpolationusing RBFs
2 DInterpolationusing RBFs
net/publication/364957487
CITATIONS READS
0 40
1 author:
Hamaidi Mohammed
Faculté des Sciences et Techniques de Tanger
7 PUBLICATIONS 42 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Hamaidi Mohammed on 09 December 2022.
import numpy as np
import time
import random
import matplotlib.pyplot as plt
NX = NY = 19
N = (NX+2)*(NY+2) # Number of nodes N = (NX+2)*(NY+2)
ep = 1 # Paramter Shape
ax, bx = 0, 1
ay, by = 0, 1
tt=time.time()
x = np.array([(bx-ax)*i/(NX+1) + ax for i in range(NX+2) for j in range(NY+2)])
y = np.array([(by-ay)*j/(NY+1) + ay for i in range(NX+2) for j in range(NY+2)])
print('Using comprehensible lists:',time.time()-tt,'seconds')
tt=time.time()
xx = np.linspace(ax,bx,NX+2)
x = (xx*np.ones([NX+2,NY+2])).T.reshape(N)
yy = np.linspace(ay,by,NX+2)
y = (yy*np.ones([NX+2,NY+2])).reshape(N)
print('Using linspace & vectors: ',time.time()-tt,'seconds')
B = exact(x,y)
print('----- Distance Matrix -----')
tt=time.time()
rx = np.abs([[x[i]-x[j] for j in range(N)] for i in range(N)])
ry = np.abs([[y[i]-y[j] for j in range(N)] for i in range(N)])
print('Using comprehensible lists: ',time.time()-tt,'seconds')
tt=time.time()
rx = np.abs([x-x[j] for j in range(N)])
ry = np.abs([y-y[j] for j in range(N)])
print('Using reduced comprehensible lists:',time.time()-tt,'seconds')
tt=time.time()
o = np.ones([N,1])
rx = np.abs(x*o-(x*o).T)
ry = np.abs(y*o-(y*o).T)
print('Using vectorial multiplications: ',time.time()-tt,'seconds')
1
View publication stats
tt = time.time()
P = RBF(rx, ry, ep)
A = np.linalg.solve(P, B)
print('Time for linear solver:',time.time()-tt,'seconds')
tt = time.time()
P = RBF(rx, ry, ep)
A = np.linalg.pinv(P).dot(B)
print('Time using pinv :',time.time()-tt,'seconds')
U_num = RBF(rx, ry, ep).dot(A)
print('-------- Errors --------------')
print('RMSE =', '%5.2e'%np.linalg.norm(B - U_num,2)) # RMS error
print('MAE =', '%5.2e'%np.max(abs(B - U_num))) # max erreor
# Test
print('----------Test----------')
NT = N//2 # Number of test nodes
x_test = np.array([(bx-ax)*random.random() + ax for i in range(NT)])
y_test = np.array([(by-ay)*random.random() + ay for i in range(NT)])
U_Exact = exact(x_test, y_test)
plt.plot(x, y,'r*')
plt.plot(x_test, y_test,'+')
plt.show()