fitting curve




# -*- coding: utf-8 -*-
"""
Created on Mon Oct 16 15:10:26 2023

@author: 307700
"""

import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt

# 定義函数 K(Vg - Vt)^m
def fit_function(Vg, K, Vt, m):
    return K * (Vg - Vt)**m

# 實際數據(替换為被分析數據)
Vg_data = np.array([1, 2, 3, 4, 5])
y_data = np.array([10, 20, 30, 40, 50])

# 初始猜測參數
initial_params = [1, 1, 1]

# 使用 curve_fit 函數進行fit
params, covariance = curve_fit(fit_function, Vg_data, y_data, p0=initial_params)

# 提取參數
K, Vt, m = params

# 輸出結果
print('吻合结果:')
print('K =', K)
print('Vt =', Vt)
print('m =', m)

# 畫圖
Vg_fit = np.linspace(min(Vg_data), max(Vg_data), 100)
y_fit = fit_function(Vg_fit, K, Vt, m)

plt.figure()
plt.plot(Vg_data, y_data, 'o', label='數據點')
plt.plot(Vg_fit, y_fit, label='吻合曲線')
plt.title('吻合曲線')
plt.xlabel('Vg')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()

English writing practice 2025-5/11

After graduating from university and working for several years, I developed the mindset that a job should be related to one’s interests. Peo...