| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 498 人关注过本帖
标题:二维插值法,想用P、T联合查W值,请高手指导一下。
只看楼主 加入收藏
xiaoshi112
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-2-10
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:2 
二维插值法,想用P、T联合查W值,请高手指导一下。
以下是数据库内容:
P    T    W
0.11    10    42.05
0.12    20    42.063
0.13    30    42.076
0.14    40    42.089
0.15    50    42.101
0.16    60    42.114
0.17    70    42.127
0.18    80    42.14
0.19    90    42.15

想用P、T查W值,请高手指导一下。

使用插值:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  模块名:InterpModule.bas
'  函数名:INLagrn2
'  功能:  实现二元全区间插值
'  参数:  n     - Integer型变量,x方向上给定结点的点数
'          m     - Integer型变量,y方向上给定结点的点数
'          x     - Double型一维数组,长度为n,存放给定n x m 个结点x方向上的n个值x(i),要求x(1)<x(2)<...<x(n)
'          y     - Double型一维数组,长度为m,存放给定n x m 个结点y方向上的m个值y(i),要求y(1)<y(2)<...<y(m)
'          z     - Double型n x m二维数组,存放给定的n x m个结点的函数值z(i,j),z(i,j) = f(x(i), y(j)), i=1,2,...,n, j=1,2,...,m
'          u     - Double型变量,存放插值点x坐标
'          v     - Double型变量,存放插值点y坐标
'  返回值:Double型,指定函数值f(u, v)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function INLagrn2(n As Integer, m As Integer, x() As Double, y() As Double, z() As Double, u As Double, v As Double) As Double
    Dim ip As Integer, ipp As Integer, iq As Integer, iqq As Integer, i As Integer, j As Integer, k As Integer, l As Integer
    Dim b(10) As Double, h As Double, w As Double
   
    If (u <= x(1)) Then
        ip = 1
        ipp = 4
    Else
        If (u >= x(n)) Then
            ip = n - 3
            ipp = n
        Else
            i = 1
            j = n
            While (((i - j) <> 1) And ((i - j) <> -1))
                l = (i + j) / 2
                If (u < x(l)) Then
                    j = l
                Else
                    i = l
                End If
            Wend
            ip = i - 3
            ipp = i + 4
        End If
    End If
   
    If (ip < 1) Then
        ip = 1
    End If
   
    If (ipp > n) Then
        ipp = n
    End If
   
    If (v <= y(1)) Then
        iq = 1
        iqq = 4
    Else
        If (v >= y(m)) Then
            iq = m - 3
            iqq = m
        Else
            i = 1
            j = m
            While (((i - j) <> 1) And ((i - j) <> -1))
                l = (i + j) / 2
                If (v < y(l)) Then
                    j = l
                Else
                    i = l
                End If
            Wend
            iq = i - 3
            iqq = i + 4
        End If
    End If
   
    If (iq < 1) Then
        iq = 1
    End If
   
    If (iqq > m) Then
        iqq = m
    End If
   
    For i = ip To ipp
        b(i - ip + 1) = 0#
        For j = iq To iqq
            h = z(i, j)
            For k = iq To iqq
                ' 二元拉格朗日公式
                If (k <> j) Then h = h * (v - y(k)) / (y(j) - y(k))
            Next k
            b(i - ip + 1) = b(i - ip + 1) + h
        Next j
    Next i
   
    w = 0#
    For i = ip To ipp
        h = b(i - ip + 1)
        For j = ip To ipp
          ' 二元拉格朗日公式
          If (j <> i) Then h = h * (u - x(j)) / (x(i) - x(j))
        Next j
        w = w + h
    Next i
   
    ' 返回函数值
    INLagrn2 = w

End Function

form代码如下:
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub test_Click()
 Dim x() As Double, y() As Double, z() As Double ', x As Single, y As Single, z As Single
 Dim m As Integer, n As Integer, s As Integer
 Dim i As Integer, j As Integer
 Dim u As Double, v As Double, w As Double
Dim str As String
cn.Open
rs.Open "H", cn, adOpenKeyset, adLockPessimistic
rs.MoveFirst
On Error Resume Next
For i = 1 To rs.RecordCount Step 1
        ReDim Preserve x(i)
        x(i) = rs.Fields("P")   '取列的数据
        rs.MoveNext
        'Debug.Print x(i)
Next i
For j = 1 To rs.RecordCount Step 1
        ReDim Preserve y(j)
        y(j) = rs.Fields("T")   '取列的数据
        rs.MoveNext
        Debug.Print y(j)
Next j
rs.MoveFirst
i = rs.RecordCount
j = rs.Fields.Count - 1
ReDim z1(i, j)
For i = 1 To rs.RecordCount Step 1
        j = 1
        z1(i, j) = CDbl(rs.Fields(2))
        For s = 3 To rs.Fields.Count - 1 '使用循环获取列的信息
            j = j + 1
            If Not IsNull(rs.Fields(s)) Then z1(i, j) = CDbl(rs.Fields(j + 1))
            'Debug.Print z1(i, j)
        Next s
        rs.MoveNext
Next i
m = rs.RecordCount
n = rs.Fields.Count - 1
cn.Close
    u = 0.11
    v = 10
    ' 插值
    w = INLagrn2(n, m, x, y, z, u, v)
    str = str & "z(" & u & ", " & v & ") = " & w
        
    MsgBox str

End Sub

Private Sub Form_Load()
 cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\main.mdb;Persist Security Info=False"
End Sub
搜索更多相关主题的帖子: 数据库 联合 
2014-01-10 15:25
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:10 
代码与问题什么关系?

无知
2014-01-10 22:23
vbvcr51
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:18
帖 子:364
专家分:1724
注 册:2013-11-3
收藏
得分:10 
好厉害啊,高等数学本来就烦,还编程,绕来绕去的,厉害。请问是数值方法吗,不是用的是matlab软件吗?

[ 本帖最后由 vbvcr51 于 2014-1-17 23:48 编辑 ]
2014-01-17 23:47
快速回复:二维插值法,想用P、T联合查W值,请高手指导一下。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035087 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved