Professional Documents
Culture Documents
Weighted Inversion
Weighted Inversion
In [6]:
x = np.array(range(1,11))
a = 2
b = 0.1
c = 0.1
d = 0.0015
e = 0.00001
y = a+b*x+c*(x**2)+d*(x**3)+e*(x**4)
rng = np.random.default_rng()
yn = y + 0.5*rng.normal (size = 10)
plt.plot(x,y,'b-')
plt.plot(x,yn,'ro')
plt.xlabel("x")
plt.ylabel("y")
plt.xlim(0, 11)
plt.ylim(0, 15)
plt.show
print(y)
print(yn)
In [2]:
import numpy as np
import matplotlib.pyplot as plt
import random as rnd
x = np.array(range(-10,10,1))
a = 1
b = 0.1
c = 0.1
d = 0.015
e = 0.00001
m = np.array([a,b,c,d,e])
y = np.matmul(Gt,m)
rng = np.random.default_rng()
yn = y + 0.5*rng.normal(size=20)
gtg = np.matmul(G,Gt)
gtginv = np.linalg.inv(gtg) #invert matrix
gtd = np.matmul(G,yn)
minv = np.matmul(gtginv,gtd)
print ("minv", minv)
#misfit
misfit = sum((yn -ycal)**2)
print("misfit", misfit)
erms = (misfit/len(x))**0.5
print(erms)
print("x",x)
print("y",y)
print("yn", yn)
Misfit 1: 5.002068674053312
RMSE: 0.5001034230063474
minv [ 9.13109646e-01 1.39497604e-01 1.09524682e-01 1.44116265e-02
-9.61532180e-05]
ycal [-4.90255688 -2.60780654 -0.96588789 0.12928407 0.78148668 1.09218
96
1.16055482 1.08343664 0.9553817 0.86862894 0.91310965 1.17644741
1.74395814 2.6986501 4.12122385 6.09007227 8.68128058 11.96862631
16.02357931 20.91530178]
misfit 4.743536915971415
0.4870080551680544
x [-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
8 9]
y [-4.9 -2.66939 -1.03904 0.07901 0.77296 1.13125 1.24256 1.19581
1.08016 0.98501 1. 1.21501 1.72016 2.60581 3.96256 5.88125
8.45296 11.76901 15.92096 21.00061]
yn [-5.03598222 -2.38501785 -1.40409834 0.45581155 1.12658912 1.3753675
7
0.71931134 1.54256314 -0.43511173 1.24282916 0.33304448 1.88473806
2.30312593 2.94306949 3.77478389 6.15331679 8.73273922 11.43078258
15.98675056 21.18234779]
In [2]:
import numpy as np
import matplotlib.pyplot as plt
import random as rnd
x = np.linspace (1,10,10)
a = 2
b = 0.2
c = 0.1
#d = 0.015
#e = 0.00001
G = [np.ones(10), x,x**2]
Gt = np.transpose(G)
m = np.array([a,b,c])
y = np.matmul(Gt,m)
yn = y +0.5*np.random.randn()
plt.plot(x, y, '-')
plt.plot(x,yn,'x')
plt.title('simple problem')
print("x",x)
print("y",y)
print("yn", yn)
x [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]
y [ 2.3 2.8 3.5 4.4 5.5 6.8 8.3 10. 11.9 14. ]
yn [ 2.10674372 2.60674372 3.30674372 4.20674372 5.30674372 6.6067437
2
8.10674372 9.80674372 11.70674372 13.80674372]
Data telah disimpan dalam file Data Inversi.txt
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
import random as rnd
x = np.array(range(-10,10,1))
a = 1
b= 0.1
c = 0.1
d = 0.015
e = 0.00001
m = np.array([a, b, c, d, e])
y = np.matmul(G,m)
rng = np.random.default_rng()
yn = y + 0.5*rng.normal(size =20)
misfit = sum((yn-y))**2
RMSE = (misfit/len(x))**0.5
In [3]:
import numpy as np
import matplotlib.pyplot as plt
# Data Anda
data_x = np.array([1.002284498, 1.585363635, 3.4110445, 4.016840429, 5.206796717])
data_y = np.array([1.195105552, 1.985314114, 2.392273696, 3.495687709, 3.495687709])
In [4]:
import numpy as np
import matplotlib.pyplot as plt
import random as rnd
a = 0.5
b = 0.8
Gt = [np.ones(5), x, x**2]
G = np.transpose(Gt) #G sudah tertranspose
m = np.array([a,b])
y = np.matmul(G,m)
gtg = np.matmul(Gt,G)
gtginv = np.linalg.inv(gtg) #invert matrix
gtd = np.matmul(G,y)
minv = np.matmul(gtginv,gtd)
print ("minv", minv)
#misfit
misfit = sum((y-ycal)**2)
print("misfit", misfit)
erms = (misfit/len(x))**0.5
print(erms)
print("x",x)
print("y",y_i)
print("y", y)
--------------------------------------------------------------------------
-
ValueError Traceback (most recent call las
t)
~\AppData\Local\Temp/ipykernel_20076/1531267816.py in <module>
16 m = np.array([a,b])
17
---> 18 y = np.matmul(G,m)
19
20 #cek misfit data sintetis
In [6]:
import numpy as np
import matplotlib.pyplot as plt
import random
y = np.matmul(Gt, m)
plt.plot(x, y, 'r-')
plt.plot(x, yn, 'bo')
plt.plot()
#Inversi
gtg = np.matmul(G, Gt)
gtg_inv = np.linalg.inv(gtg)
gtd = np.matmul(G, yn)
m_inv = np.matmul(gtg_inv, gtd)
plt.plot(x, y, 'r-')
plt.plot(x, yn, 'bo')
plt.plot(x, ycal, 'y')
e = 1
plt.errorbar(x, ycal, yerr = e, fmt = '.', linewidth = 1, capsize = 5)
plt.plot()
Out[6]:
[]
In [7]:
Out[7]:
[]
In [ ]: