python實現S-N曲線,P-S-N曲線
瀏覽:2209
S-N曲線是什么?
S-N曲線,也稱為應力-壽命曲線,是疲勞分析中最基本的工具。它描述了結構在循環載荷下,應力水平(S) 與至失效的循環次數(N) 之間的關系。
常用數學表達式:
對公式兩邊取對數,得到線性方程:
使用最小二乘法對數據點進行線性回歸,擬合出最佳直線即可獲得S-N曲線。這條直線也叫中值S-N曲線。
下面為python實現S-N,P-S-N曲線具體方式,最終獲取的結果為:
第一步當然是最小二乘法的實現:
def linear_least_squares_fit_y(x: np.ndarray, y: np.ndarray) -> Dict[str, Any]:
"""
對 y ~ x 進行最小二乘直線擬合:y = a*x + b
Args:
x: 自變量數組
y: 因變量數組
Returns:
字典包含 a, b, y_pred, residuals, metrics 等
"""
x = np.asarray(x)
y = np.asarray(y)
if len(x) != len(y):
raise ValueError("x 和 y 長度不一致")
if len(x) < 2:
raise ValueError("至少需要兩個點才能擬合")
a, b = np.polyfit(x, y, 1)
y_pred = a * x + b
residuals = y - y_pred
ss_res = np.sum(residuals ** 2)
ss_tot = np.sum((y - np.mean(y)) ** 2)
r_squared = 1 - (ss_res / ss_tot) if ss_tot != 0 else 0.0
rmse = np.sqrt(ss_res / len(x))
metrics = {
'r_squared': r_squared,
'rmse': rmse,
'ss_res': ss_res,
'ss_tot': ss_tot,
'n': len(x)
}
print(f"成功擬合直線: y = {a:.4f}x + {b:.4f}, R2 = {r_squared:.4f}")
return {
'slope': a,
'intercept': b,
'y_pred': y_pred,
'residuals': residuals,
'metrics': metrics
}
下面將實現特定可靠度,特定置信度下的SN繪制,以及源代碼下載。
以下內容為付費內容,請購買后觀看
包含1個文件
詳細實現SN曲線的繪制的python源代碼,同時考慮特定存活率和置信度。
網盤鏈接
通過網盤分享的文件:01_SN_curv...
技術鄰APP
工程師必備
工程師必備
- 項目客服
- 培訓客服
- 平臺客服
TOP




















