Dim a() As String, b() As String
Private Sub Command1_Click()
Dim temp1 As String
Dim i As Integer, k As Integer
temp1 = Text1.Text
a = Split(temp1, ",")
lenolds = Len("->")
For i = 0 To UBound(a)
s = a(i)
j = InStr(s, "->")
Do While j >0
ReDim Preserve b(i, k)
b(i, k) = Val(Left(s, j + lenolds))
s = Left(s, j - 1) + "->" + Mid(s, j + lenolds + 1)
k = k + 1
j = InStr(s, "老侍->")
Loop
ReDim Preserve b(i, k)
b(i, k) = s
Next i
For i = 0 To UBound(a)
For j = 0 To k
Text2.Text = Text2.Text + b(i, j)
Next j
Next i
End Sub
题主的(缓码4自变量1因变量)多元函数的拟合matlab程序。可以用nlinfit非线性回归函数来做段察(也可以用lsqcurvefit函数)。实现代码:
x1=[0.55 0.65 0.65 0.65 0.65 0.55 0.55 0.55 0.65]'
x2=[1.6 1.6 1.4 1.6 1.4 1.4 1.6 1.4 1.4]'
x3=[20 20 20 10 10 20 20 20 20]'
x4=[10 10 10 10 10 10 12 12 12]'
Y=[1.848 3.145 3.337 3.022 3.188 1.97 1.63 1.621 2.534]'
X=[x1 x2 x3 x4]
n=length(x1)
a0=rand(1,5)
func=@(a,X)(a(1)+a(2)*X(:,1)+a(3)*X(:,2)+a(4)*X(:,3)+a(5)*X(:,4))
[a,r,J] = nlinfit(X,Y,func,a0)a
Y1=func(a,X)
[Y Y1]
运行上述代码,可以得到
a1= -1.52778571412534;a2= 11.4823809522886;a3= -0.359047619087202 ;a4= 0.00441190476147387;a5=-0.23363095238449
多元函数表达式,y=a1+a2*x1+a3*x2+a4*x3+a5*x4
nlinfit与lsqcurvefit两者区别并不扰燃哪太大,前者用回归的方法来求解,而后者用最小二乘法来求解,两者都可以用于非线性函数和线性函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)