Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function to solve system of equations 1

Status
Not open for further replies.

Devolder

Technical User
Mar 14, 2008
1
IT
Say I want to solve a system of equations. Argument is the matrix of the coefficients. The function returns solution. Can I write a function like the following?
System(systarray() as double) as double()
Code…….
X=..
Y=…
Z=…
System=(x,y,z)
Debug.print System
End function

Say for example I have a system with three variables
3x + 7y+4z=1
9x + 12y+6z=2
31x + 27y+41z=10
How do I enter the arguments of the array? Is the following correct?
System (3,7,4,1; 9,12,6,2; 31,27,41,10)






 
You can:
Code:
Function System(systarray() As Double) As Double()
lBase = LBound(systarray, 1)
n = UBound(systarray, 1) - lBase + 1
ReDim System(1 To n)
       'Code…….
       '...
       System(i) = X(i)
       '...
End Function

Sub Test()
Dim A(1 To 3, 1 To 4) As Double, Output() As Double
'A(1,1)=...
Output = System(A)
Debug.Print Output(i)
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top