Home > Software engineering >  Vba in the matrix inverse operation
Vba in the matrix inverse operation

Time:09-19

Hope to be able to write a function in the vba
1. The input parameters (x1, x2, x3,... Xn) and (y1, y2, y3... Yn), that is, two range
2. Then a n * n are formed by these parameters of matrix, the inverse matrix and the matrix
3. Then use the inverse matrix, multiplied by a vector, the calculation results for another vector
4. The vector as the output


In fact, I just want to realize the cubic spline interpolation!!!!!!

Now in the third step walk!!!!!! Matrix with two arrays, said in the second step, and don't know right,,,

Pray god know!!!!!!

CodePudding user response:

"Baidu search" vba cubic spline interpolation

CodePudding user response:

Is that I already know about cubic spline algorithm, is stuck in the inverse matrix a, namely red font in the following code statement is the only statement cannot run through, asking great god answer!!!!!!

Public Function spline (x As the Range, y As Range)

Dim l1 As Integer

L1=x.R ows. Count

Dim l2 As Integer

L2=y.R ows. Count

If l1 & lt;> L2 Then

Spline="Error: the Range of the count does not match"
GoTo endnow

End the If

Dim (a) As a Double
Dim aInv () As a Double
Dim As Integer I
Dim (b) As a Double
Dim (k) As a Double
Dim n As Integer

N=l1

ReDim a (1 To n, 1 To n)
ReDim aInv (1 To n, 1 To n)
ReDim b (1 To n)

'the first point
A (1, 1)=2/(x - x (1) (2))
A (1, 2)=1/(x - x (1) (2))
B (1)=3 * (y (2) - y (1))/((x (2) - x (1)) ^ 2)

'n points
A (n, n)=2/(n) (x - x (n - 1))
A (n, n - 1)=1/(n) (x - x (n - 1))
B (n)=3 * (y (n) - y (n - 1))/((n) (x - x (n - 1)) ^ 2)

'the points I
For I=2 To n - 1

A (I, I - 1)=1/(x (I) - x (I - 1))
A (I, I + 1)=1/(I + 1) (x - x (I))
A (I, I)=2 * a (I, I - 1) + 2 * a (I, I + 1)
B (I)=3 * (y (I) - y (I - 1))/(x (x (I) - (I - 1)) ^ 2) + 3 * (y (I + 1) - y (I))/((x (I + 1) - x (I)) ^ 2)

Next I

aInv=Application. WorksheetFunction. MInverse (a)

Spline=aInv (1, 3)

Endnow:
End the Function

  •  Tags:  
  • VBA
  • Related