Chú lập thế này ko ổn về mặt cơ sở dữ liệu roài.e có 1 file như sau.
a(c) nào có thể viết code nội suy cho e với.
bản chất vẫn là nội suy 1 chiều.nhưng e chưa thành thạo lắm nên vẫn chưa viết được
e có 1 file như sau.
a(c) nào có thể viết code nội suy cho e với.
bản chất vẫn là nội suy 1 chiều.nhưng e chưa thành thạo lắm nên vẫn chưa viết được
Option Explicit
Function NoiSuy3TS(VungTra As Range, Truc, Duong As String, LLg As Double) As Double
Dim LMD As Range, LLX As Range, sRng As Range
Dim Rws As Long, Col As Byte
Dim Eyc As Double, X0 As Double, X1 As Double
Set LMD = VungTra.Cells(1).Resize(VungTra.Rows.Count)
Set LLX = VungTra.Cells(, 1).Resize(, VungTra.Columns.Count)
Set sRng = LMD.Find(Truc & Duong, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
Rws = sRng.Row
Else
NoiSuy3TS = 1 * 10 ^ (-9): Exit Function
End If
With Application.WorksheetFunction
X0 = .Lookup(LLg, LLX)
End With
Set sRng = LLX.Find(X0): Col = sRng.Column
X1 = sRng.Offset(, 1).Value: Eyc = Cells(Rws, Col).Value
NoiSuy3TS = Eyc + (LLg - X0) * (Cells(Rws, Col + 1).Value - Eyc) / (X1 - X0)
End Function
Liệu a có thể viết code cho e file này không?để e hoàn thành file tính toán thuỷ văn.chỉ còn bảng tra này e không xử lý được.
http://www.mediafire.com/?5zjzyetidmm
Function NS3YT(VungTra As Range, xeduong As Range, taitrong As String, Duong As String, luuluong As Double) As Double
Dim i As Integer
Dim j As Integer
Dim X1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim hang As Integer
For i = 1 To xeduong.Cells.Count
If Application.WorksheetFunction.Match(taitrong & Duong, xeduong, 0) = i Then
hang = i + 1
End If
Next i
For j = 1 To VungTra.Cells.Count
If VungTra.Cells(1, j) <= luuluong And VungTra.Cells(1, j + 1) >= luuluong Then
X1 = VungTra.Cells(1, j): x2 = VungTra.Cells(1, j + 1)
y1 = VungTra.Cells(hang, j): y2 = VungTra.Cells(hang, j + 1)
NS3YT = y1 + (y2 - y1) * (luuluong - X1) / (x2 - X1)
End If
Next j
End Function
E đã tự mày mò viết ra file này theo cách hiểu của e (tại e chưa viết bao giờ nên nhìn vào code của a e không có hiểu lắm)
.a xem và cho e ý kiến nhé
PHP:Option Explicit Function NS3YT(VungTra As Range, xeduong As Range, taitrong As String, _ Duong As String, luuluong As Double) As Double Dim i As Integer, j As Integer Dim X1 As Double, x2 As Double, y1 As Double, y2 As Double Dim hang As Integer For i = 1 To xeduong.Cells.Count If Application.WorksheetFunction.Match(taitrong & Duong, xeduong, 0) = i Then hang = i + 1 End If Next i For j = 1 To VungTra.Cells.Count If VungTra.Cells(1, j) <= luuluong And VungTra.Cells(1, j + 1) >= luuluong Then X1 = VungTra.Cells(1, j): x2 = VungTra.Cells(1, j + 1) y1 = VungTra.Cells(hang, j): y2 = VungTra.Cells(hang, j + 1) NS3YT = y1 + (y2 - y1) * (luuluong - X1) / (x2 - X1) End If Next j End Function
Function noisuy2(vungtra As Range, hang As Double, cot As Double) As Double
'ham noi suy 2 chieu
Dim ktra As Boolean
Dim i As Integer, j As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
For i = 2 To vungtra.Cells.Count
If vungtra.Cells(1, i) <= cot And vungtra.Cells(1, i + 1) >= cot Then
For j = 2 To vungtra.Cells.Count
ktra = False
If vungtra.Cells(j, 1) <= hang And vungtra.Cells(j + 1, 1) >= hang Then
x1 = vungtra.Cells(1, i): x2 = vungtra.Cells(1, i + 1)
y1 = vungtra.Cells(j, 1): y2 = vungtra.Cells(j + 1, 1)
a11 = vungtra.Cells(j, i): a12 = vungtra.Cells(j, i + 1)
a21 = vungtra.Cells(j + 1, i): a22 = vungtra.Cells(j + 1, i + 1)
t1 = (a12 - a11) * (cot - x1) / (x2 - x1) + a11
t2 = (a22 - a21) * (cot - x1) / (x2 - x1) + a21
noisuy2 = (t2 - t1) * (hang - y1) / (y2 - y1) + t1
End If
Next j
ktra = True
End If
Next i
If ktra = False Then
MsgBox "xem lai di nhe-kiennguyen", vbInformation
Exit Function
End If
End Function
Option Explicit
Function NS2_GPE(VungTra As Range, xX As Double, yY As Double, Optional Vung2 As Boolean = True)
'Hàm Noi Suy 2 Chieu Cai Tién:'
Dim Col As Byte, Rws As Long
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
Dim RgNg As Range, RgDoc As Range, ClsX As Range, ClsY As Range
Col = VungTra.Columns.Count: Rws = VungTra.Rows.Count
Set RgNg = VungTra.Cells(1, 1).Resize(, Col - 1)
y1 = Application.WorksheetFunction.Lookup(yY, RgNg)
Set ClsY = RgNg.Find(y1, , xlFormulas, xlWhole)
y2 = ClsY.Offset(, 1).Value: Col = ClsY.Column
If Vung2 Then
Set RgDoc = VungTra.Cells(1).Offset(1 + Rws \ 2).Resize(Rws \ 2)
Else
Set RgDoc = VungTra.Cells(1, 1).Resize(Rws \ 2)
End If
x1 = Application.WorksheetFunction.Lookup(xX, RgDoc)
Set ClsX = RgDoc.Find(x1): Rws = ClsX.Row
x2 = ClsX.Offset(1).Value
a11 = Cells(Rws, Col): a22 = Cells(Rws + 1, Col + 1)
a12 = Cells(Rws, Col + 1): a21 = Cells(Rws + 1, Col)
t1 = (a12 - a11) * (yY - y1) / (y2 - y1) + a11
t2 = (a22 - a21) * (yY - y1) / (y2 - y1) + a21
NS2_GPE = (t2 - t1) * (xX - x1) / (x2 - x1) + t1
End Function
e đã xem bài viết của a.(1) Hình như cách tính nội suy 2 chiều của bạn chưa đúng lắm
Với hàm của mình viết tại đây: http://www.giaiphapexcel.com/forum/showthread.php?5828-hàm-nội-suy-1-chiều-và-2-chiều/page2
. . . nhưng e thấy về bản chất thì code e viết với của a là giống nhau mà.
vậy tại sao của e lại không ra được như vậy?mong a trả lời.
(mà a à.e thấy a trình bày rất ổn.nhưng a có thể khi viết dùng tên các biến dễ hiểu hơn không,như xX=hàng , yY = cột , tên các biến RgNg,RgDoc... cũng nên đổi..đó chỉ là ý kiến của e thôi)
e đã xem của a.nó đúng rồi.PHP:Option Explicit Function NS2_GPE(VungTra As Range, xX As Double, yY As Double, Optional Vung2 As Boolean = True) 'Hàm Noi Suy 2 Chieu Cai Tién:' Dim Col As Byte, Rws As Long Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double Dim t1 As Double, t2 As Double Dim RgNg As Range, RgDoc As Range, ClsX As Range, ClsY As Range Col = VungTra.Columns.Count: Rws = VungTra.Rows.Count Set RgNg = VungTra.Cells(1, 1).Resize(, Col - 1) y1 = Application.WorksheetFunction.Lookup(yY, RgNg) Set ClsY = RgNg.Find(y1, , xlFormulas, xlWhole) y2 = ClsY.Offset(, 1).Value: Col = ClsY.Column If Vung2 Then Set RgDoc = VungTra.Cells(1).Offset(1 + Rws \ 2).Resize(Rws \ 2) Else Set RgDoc = VungTra.Cells(1, 1).Resize(Rws \ 2) End If x1 = Application.WorksheetFunction.Lookup(xX, RgDoc) Set ClsX = RgDoc.Find(x1): Rws = ClsX.Row x2 = ClsX.Offset(1).Value a11 = Cells(Rws, Col): a22 = Cells(Rws + 1, Col + 1) a12 = Cells(Rws, Col + 1): a21 = Cells(Rws + 1, Col) t1 = (a12 - a11) * (yY - y1) / (y2 - y1) + a11 t2 = (a22 - a21) * (yY - y1) / (y2 - y1) + a21 NS2_GPE = (t2 - t1) * (xX - x1) / (x2 - x1) + t1 End Function
(1)
nhưng câu hỏi e muốn hỏi tiếp là nếu có nhiều hơn các vùng mưa có đến IX vùng mưa thì khi đó ko thể dùng Optional Vung2 As Boolean = True.
màa à.làm thế nào để tô màu như a vậy?nhìn có màu vào dễ kiểm tra hơn hẳn (3)
((2) mà cái file kết quả xổ xố.a để pass code,liệu có thể cho biết được khôngg ạ?)
Option Explicit
[B]Function NS2_4_GPE(VungTra As Range, xX As Double, yY As Double, Optional Vung As Byte = 1)[/B]
'Hàm Noi Suy 2 Chieu Cai Tién:'
Dim Col As Byte, Rws As Long
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
Dim RgNg As Range, RgDoc As Range, ClsX As Range, ClsY As Range
Col = VungTra.Columns.Count: Rws = VungTra.Rows.Count
Set RgNg = VungTra.Cells(1, 1).Resize(, Col - 1)
y1 = Application.WorksheetFunction.Lookup(yY, RgNg)
Set ClsY = RgNg.Find(y1, , xlFormulas, xlWhole)
y2 = ClsY.Offset(, 1).Value: Col = ClsY.Column
Rws = Rws \ 4 [COLOR=red]'<=|'[/COLOR]
Set RgDoc = VungTra.Cells(1).Offset(1 + (Vung - 1) * Rws).Resize(Rws)
x1 = Application.WorksheetFunction.Lookup(xX, RgDoc)
Set ClsX = RgDoc.Find(x1): Rws = ClsX.Row
x2 = ClsX.Offset(1).Value
a11 = Cells(Rws, Col): a22 = Cells(Rws + 1, Col + 1)
a12 = Cells(Rws, Col + 1): a21 = Cells(Rws + 1, Col)
t1 = (a12 - a11) * (yY - y1) / (y2 - y1) + a11
t2 = (a22 - a21) * (yY - y1) / (y2 - y1) + a21
NS2_4_GPE = (t2 - t1) * (xX - x1) / (x2 - x1) + t1
[B]End Function[/B]
Function NoiSuy2_CT(VungTra As Range, hangcantra As Double, _
cotcantra As Double, vungmua As Integer) As Double
'Ham Noi Suy 2 Chieu cai tien GPE.COM (kiennguyen)'
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
'x1,x2 ung voi cot : y1,y2 ung voi hang'
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
Dim ktra As Boolean
Dim hangthu1 As Range, cotthu1 As Range
Dim Rw As Range, Cl As Range
Set hangthu1 = VungTra.Cells(1, 2).Resize(1, VungTra.Columns.Count)
Set cotthu1 = VungTra.Cells((VungTra.Rows.Count - 1) / 5 * (vungmua - 1) + 2, 1).Resize(7, 1)
'neu co nhieu vung mua hon thi thay 5 = tong vungmua'
'neu co nhieu hang hon trong 1 vung mua hon thi thay 7 = tong so hang cua 1vungmua'
For Each Cl In hangthu1
If Cl <= cotcantra And Cl.Offset(, 1) >= cotcantra Then
ktra = False
y1 = Cl: y2 = Cl.Offset(, 1)
For Each Rw In cotthu1
If Rw <= hangcantra And Rw.Offset(1) >= hangcantra Then
x1 = Rw: x2 = Rw.Offset(1)
a11 = Cells(Rw.Row, Cl.Column): a12 = Cells(Rw.Row, Cl.Column + 1)
a21 = Cells(Rw.Row + 1, Cl.Column): a22 = Cells(Rw.Row + 1, Cl.Column + 1)
t1 = a11 + (a12 - a11) * (cotcantra - y1) / (y2 - y1)
t2 = a21 + (a22 - a21) * (cotcantra - y1) / (y2 - y1)
NoiSuy2_CT = t1 + (t2 - t1) * (hangcantra - x1) / (x2 - x1)
End If
Next Rw
ktra = True
End If
Next Cl
If ktra = False Then
MsgBox "xem lai di nhe", vbInformation
Exit Function
End If
End Function
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 1
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 2