1
|
%UserProfile%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\
| cs |
1
|
ren *.* *.jpg
| cs |
1
|
%UserProfile%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\
| cs |
1
|
ren *.* *.jpg
| cs |
1
2
3
4
5
6
|
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df # with this command you can see your file
| cs |
1
2
3
|
vars=[1.,0.]
print get_residual(vars, x, data)
print sum(get_residual(vars, x, data)**2)
| cs |
1
|
from lmfit import minimize, parameters
| cs |
1
|
conda install -c conda-forge lmfit
| cs |
1
|
from lmfit import minimize, parameters
| cs |
1
2
3
4
5
6
7
8
|
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
x =np.array([0.,1.,2.,3.,])
data=np.array([1.3,1.8,5.,10.7])
plt.plot(x,data,'d')
| cs |
1
2
3
4
|
plt.scatter(x,data)
xarray=np.arange(-1,4,0.1)
plt.plot(xarray,xarray**2,'r-') #Manually Fitting - Red
plt.plot(xarray,xarray**2+1,'g-') #Better Fitting - Green
| cs |
1
2
3
4
5
6
7
|
def get_residual(vars, x, data):
a = vars[0]
b = vars[1]
model = a*x**2 + b
return data - model
| cs |
1
2
3
|
vars=[1.,0.]
print(get_residual(vars, x, data))
print(sum(get_residual(vars, x, data)**2))
| cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from scipy.optimize import leastsq
vars=[0.,0.]
out = leastsq(get_residual, vars, args=(x,data))
# here the out gives 1.06734694, 0.96428571
vars=[1.06734694, 0.96428571]
print(sum(get_residual(vars, x, data)**2))
plt.scatter(x,data)
xarray=np.arange(-1,4,0.1)
plt.plot(xarray,xarray**2,'r-') #Manually Fitting - Red
plt.plot(xarray,xarray**2+1,'g-') #Better Fitting - Green
fitted = vars[0]*xarray**2 + vars[1]
plt.plot(xarray,fitted, 'b-') #leastsq fit
| cs |
1
2
|
spec = pd.read_table(r'C...Average.txt', sep=' ', names=['rows', 'column'])
spec
| cs |
1
2
3
4
5
6
|
x = spec.rows
y = spec.column
plt.rcParams["figure.figsize"] = (20,10) #Changing figure size
plt.xlabel('Wave Length')
plt.ylabel('Value')
plt.plot(x, y)
| cs |
Problem: Calculate the gravitational acceleration on Earth.
The force on an object of mass \(m_1\) near the surface of the Earth is
\[\begin{aligned} F = m_1 g\end{aligned}\]
where \(g\) is the gravitational acceleration that we are interested in. Newton’s gravity formula is given as below
\[\begin{aligned} F = m_1 g = G\frac{m_1 m_2}{r^2}\end{aligned}\]
where \(m_2\) is the mass of the Earth, \(r\) is the radius of the Earth, and \(G\) is the gravitational constant. Each value is given as below
\(G = 6.67\times 10^{-11} \left[\frac{m^3}{kg s^2}\right]\)
\(m_{Earth}=m_2 = 5.97 \times 10^{24} [kg]\)
\(r_{Earth}=r = 6371 [km]\)
Substitute all the values
\[\begin{aligned} F = m_1 g &= G\frac{m_1 m_2}{r^2}\\ g &= G \frac{m_2}{r^2} = 6.67\times 10^{-11}\frac{5.97 \times 10^{24}}{ 6371^2 \times 1000^2 \left[ \frac{m}{km}\right]}=9.81 \left[ \frac{m}{s^2}\right]\end{aligned}\]