python实现S-N曲线,P-S-N曲线
浏览:1800
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}, R² = {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




















