[英]How do I get the polynomial regression coefficients using Excel VBA?
I have two columns, say x
and f(x)
. 我有两列,比如x
和f(x)
。 I want to get the coefficients of the second degree equation after doing the polynomial regression in Excel VBA. 我想在Excel VBA中进行多项式回归后得到二次方程的系数。
I'm a rookie in Excel VBA and have no clue what to do. 我是Excel VBA的新手,不知道该怎么做。
For example- 例如-
xy XY
-1 -1 -1 -1
0 3 0 3
1 2.5 1 2.5
2 5 2 5
3 4 3 4
5 2 5 2
7 5 7 5
9 4 9 4
The coefficients for the equation f(x)=a*x^2+b*x+c
will be 等式f(x)=a*x^2+b*x+c
的系数将是
a= -.008571
b= 0.99555
c= 1.648439.
In terms of using code for this, use LINEST
, one way below 在使用代码方面,请使用LINEST
,如下所示
Sub Quaddy()
Dim X
X = Application.Evaluate("=linest(b1:B8,A1:A8^{1,2})")
MsgBox "Equation is y=" & Format(X(1), "0.###") & "x2+" & Format(X(2), "0.###") & "x+" & Format(X(3), "0.###")
End Sub
This is shown in the Excel chart below 这显示在下面的Excel图表中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.