虽然可能但是matlab、mathmatica更好用,少掉点头发还是用了python。
一维也算是比较简单了,我看很多哥哥们都喜欢收费,我想了想肯定是免费。
这里设置了一个函数,Film(),在前面自己改一下波长lam还有一些个initial condition
import numpy as np
from matplotlib import pyplot as plt
class Film():
def __init__(self, n_list, d_list, labels=None, nd=True, lambda0=550):
self.n_list = n_list
self.nd = nd
self.lambda0 = lambda0
self.d_list = d_list
self.labels = labels
def __part_fit(self, rect_list, theta_cos, n_list, j):
rect_list = np.array(rect_list, dtype=np.complex128)
rect_list = rect_list.transpose(3, 0, 1, 2)
n_theta_cos = n_list[j][-1] * theta_cos
Y = []
for i in range(rect_list.shape[0]):
rect = np.eye(2)
for k in range(rect_list[i].shape[0]):
rect = np.dot(rect, rect_list[i, k])
rect = np.dot(rect, np.array([[1], [n_theta_cos[i]]]))
Y.append(rect)
Y = np.array(Y)
Y = Y[:, 1, 0] / Y[:, 0, 0]
return Y
def fit(self, wavelength, theta=0):
if type(wavelength) == float or type(wavelength) == int:
wavelength = [wavelength]
self.wavelength = np.array(wavelength)
n_list = []
n_lambda0 = []
for i in self.n_list:
n_list.append([])
n_lambda0.append([])
for j in i:
if type(j).__name__ != 'function':
n_list