r 语言里拟合函数的参数估计

# 自定义函数
f = function(x,a,b,c,d){
  (a*x^2+b*x+c)*sinpi(x-1.5)+d
}

# dt是实现导入的数据,有2列,x和y
m.2 <- nls(y ~ f(x,a,b,c,d), data = dt, start = list(a = 0, b = 0,c=0,d=0), trace = T)

# 展示abcd的参数拟合结果
summary(m.2)

# 简单画出拟合的曲线
plot(x,f(x,0.009507576,0.229666667,1.089791667,45.485875000))

函数拟合时,自定的函数用最小二乘法计算出参数结果。

猜你喜欢

转载自blog.csdn.net/u012891477/article/details/89709610