完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这段多上的带码如何实现,求大神
Public Sub LinearAndCubicFit(X() As Single, Y() As Single, n As Integer, n1 As Integer, n2 As Integer) '**** 此函数为“直线-三次抛物线拟合”算法( 见西安交通大学《电机测试技术》)**** Dim n∑Xi As Single Dim n∑XiE2 As Single Dim n∑Yi As Single Dim n∑XiYi As Single Dim n1∑Xi As Single Dim n1∑Yi As Single Dim n1∑XiE2 As Single Dim n1∑XiYi As Single Dim n2∑XiE2 As Single Dim n2∑XiE3 As Single Dim n2∑XiE4 As Single Dim n2∑XiE5 As Single Dim n2∑XiE6 As Single Dim n2∑XiE2Yi As Single Dim n2∑XiE3Yi As Single Dim A(1 To 3, 1 To 3) As Single '方程组“系数矩阵” Dim C(1 To 3) As Single '方程组“常数项向量” Dim B() As Single ReDim B(1 To 3) As Single '方程组“解向量” Dim Q_13(1 To 20) As Single '直线-三次抛物线拟合之“残差平方和” Dim n1∑ViE2 As Single Dim n2∑ViE2 As Single Dim i, j As Integer Dim X0 As Single For i = 1 To n n∑Xi = n∑Xi + X(i) n∑Yi = n∑Yi + Y(i) n∑XiYi = n∑XiYi + X(i) * Y(i) n∑XiE2 = n∑XiE2 + X(i) ^ 2 Next i DoEvents For i = n2 + 1 To n n1∑Xi = n1∑Xi + X(i) n1∑Yi = n1∑Yi + Y(i) n1∑XiE2 = n1∑XiE2 + X(i) ^ 2 n1∑XiYi = n1∑XiYi + X(i) * Y(i) Next i DoEvents For i = 1 To n2 n2∑XiE2 = n2∑XiE2 + X(i) ^ 2 n2∑XiE3 = n2∑XiE3 + X(i) ^ 3 n2∑XiE4 = n2∑XiE4 + X(i) ^ 4 n2∑XiE5 = n2∑XiE5 + X(i) ^ 5 n2∑XiE6 = n2∑XiE6 + X(i) ^ 6 n2∑XiE2Yi = n2∑XiE2Yi + X(i) ^ 2 * Y(i) n2∑XiE3Yi = n2∑XiE3Yi + X(i) ^ 3 * Y(i) Next i DoEvents j = 1 For X0 = 0.3 To 1.1 Step 0.05 A(1, 1) = n A(1, 2) = n∑Xi: A(2, 1) = A(1, 2) A(1, 3) = n2∑XiE3 - 3 * X0 * n2∑XiE2 - 3 * X0 ^ 2 * n1∑Xi + n1 * X0 ^ 3: A(3, 1) = A(1, 3) A(2, 2) = n∑XiE2 A(2, 3) = n2∑XiE4 - 3 * X0 * n2∑XiE3 - 3 * X0 ^ 2 * n1∑XiE2 + X0 ^ 3 * n1∑Xi: A(3, 2) = A(2, 3) A(3, 3) = n2∑XiE6 - 6 * X0 * n2∑XiE5 + 9 * X0 ^ 2 * n2∑XiE4 + 9 * X0 ^ 4 * n1∑XiE2 - 6 * X0 ^ 5 * n1∑Xi + n1 * X0 ^ 6 C(1) = n∑Yi C(2) = n∑XiYi C(3) = n2∑XiE3Yi - 3 * X0 * n2∑XiE2Yi - 3 * X0 ^ 2 * n1∑XiYi + X0 ^ 3 * n1∑Yi B = SolvingEquations(A(), C(), 3) '调解方程组函数 Dim ValueTemp As Single For i = n2 + 1 To n ValueTemp = Y(i) - (B(1) + B(2) * X(i) + B(3) * (X0 ^ 3 - 3 * X0 ^ 2 * X(i))) ValueTemp = ValueTemp ^ 2 n1∑ViE2 = n1∑ViE2 + ValueTemp Next i For i = 1 To n2 ValueTemp = Y(i) - (B(1) + B(2) * X(i) + B(3) * (X(i) ^ 3 - 3 * X0 * X(i) ^ 2)) ValueTemp = ValueTemp ^ 2 n2∑ViE2 = n2∑ViE2 + ValueTemp Next i Q_13(j) = n1∑ViE2 + n2∑ViE2 If Q_13(1) >= Q_13(j) Then Q_13(1) = Q_13(j) P_X0 = X0 AA(0) = B(1) + B(3) * P_X0 ^ 3 AA(1) = B(2) - 3 * B(3) * P_X0 ^ 2 BB(0) = B(1) BB(1) = B(2) BB(2) = -3 * B(3) * P_X0 BB(3) = B(3) End If j = j + 1 n1∑ViE2 = 0: n2∑ViE2 = 0 Next X0 P_QLineCurve = Q_13(1) End Sub |
|
相关推荐
2个回答
|
|
使用VB写的吗?
|
|
|
|
本帖最后由 loge2012 于 2016-7-18 09:56 编辑
对,VB写的 网上也可以搜到的,准备用labview来做软件,好多这样的代码无从下手 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
879 浏览 2 评论
1318 浏览 1 评论
937 浏览 0 评论
新手求助,从示波器导出来csv类型的波形数据,怎么用labview读取csv文件还原波形,求助各位大佬,感谢感谢!!!
1431 浏览 2 评论
Labview 信号处理 瞬态测量 连线出现错误提示,请教各位前辈!麻烦请各位帮忙看一下?
6829 浏览 2 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-6 08:19 , Processed in 0.764391 second(s), Total 76, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号