Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
interpolation1D/test.py
Go to the documentation of this file.
1# /opt/local/bin/python3.13 test.py
2import sys, string, os
3import numpy as np
4import matplotlib.pyplot as plt
5from matplotlib import cm
6plt.rcParams['text.usetex'] = True
7sys.path.append("../../python")
8from modlibUtils import *
9sys.path.append("../../build/tools/pyMoDELib")
10import pyMoDELib
11
12
13#XiYi=np.array([[0.0,1.0],
14# [30.0,10.0],
15# [54.0,0.5],
16# [90.0,45.0],
17# [180-54.0,0.5],
18# [180-30.0,17.0]
19# ])
20
21XiYi=np.random.rand(6, 2)
22dX=np.max(XiYi[:,0])-np.min(XiYi[:,0])
23
24extrapolation=pyMoDELib.ExtrapolationMethod(2,1.1*dX) # 0=default, 1=linear, 2=periodic
25lagrangeInterp=pyMoDELib.LagrangeInterpolant(XiYi,extrapolation)
26linearInterp=pyMoDELib.LinearInterpolant(XiYi,extrapolation)
27
28X=np.linspace(np.min(XiYi[:,0])-2, np.max(XiYi[:,0])+2, num=10000, endpoint=True)
29Y1=np.zeros(len(X))
30Y2=np.zeros(len(X))
31for i in range(len(X)):
32 Y1[i]=lagrangeInterp.f(X[i])
33 Y2[i]=linearInterp.f(X[i])
34# Y1[i]=lagrangeInterp.atPeriodic(X[i],np.min(XiYi[:,0])-0.2,np.max(XiYi[:,0])+0.2)
35# Y2[i]=linearInterp.atPeriodic(X[i],np.min(XiYi[:,0])-0.2,np.max(XiYi[:,0])+0.2)
36
37
38fig1 = plt.figure()
39ax1=plt.subplot(1,1,1)
40ax1.plot(XiYi[:,0], XiYi[:,1],'o')
41#ax1.plot(X, Y1,label='lagrange')
42ax1.plot(X, Y2,label='linear',linestyle='dashed')
43plt.legend()
44ax1.grid()
45plt.show()