×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How I can implement a matrix inversion using Gauss-Seidel Method?

How I can implement a matrix inversion using Gauss-Seidel Method?

How I can implement a matrix inversion using Gauss-Seidel Method?

(OP)
Hi guys,I need to implement one VB 5.0 aplication, witch decoy a imagem jammed to the same imagem, but clear now. I will use a calculus with two matrix, calls Matrix_A and Matrix_B, right ? Well, I can't use the matrix invertion, using the Gauss-Seidel's linear system calculation method. How I can implement a matrix inversion using Gauss-Seidel Method in Visual Basic 5.0 ?

Thanks for all !!!

RE: How I can implement a matrix inversion using Gauss-Seidel Method?

Simply put, you can't.

The Gauss-Seidel method is an iterative method to solve a system of equations but it does not use (or return) the matrix inverse. If all you are interested in is the matrix inverse, you will have to find a different algorithm (such as LU decomposition or a modified version of Gauss-Jordan). If all you are interested in is solving a system of linear equations, the Gauss-Seidel method will do just fine.

RE: How I can implement a matrix inversion using Gauss-Seidel Method?

(OP)
Thank's for you explaination ! I wanna implement the Gauss-Seidel Linear solve system. Forget the matrix inversion, I need knows only how a get this in VB 5.0. Can you help me ?

RE: How I can implement a matrix inversion using Gauss-Seidel Method?

Here is an implementation of Gauss-Seidel in Visual Basic. Before you use it though, there are a few words of warning: the Gauss-Seidel method works best on diagonally dominant systems of equations (ie the elements on the diagonal are  larger than the other elements in the array). I have included a function to test for this condition (the GaussSeidelConverge function) if this function returns "true", the system is guaranteed to converge; if it does not return "true" it is not guaranteed (but that does not necessarily mean it will diverge). One of the optional arguments to the main routine is "RelaxCoeff", this is a relaxation coefficient that may help with the solving process. This coefficient can take on values from 0 to 2 (1 is the default, it is the same as not using relaxation). If the system is guaranteed to converge, you can use a value between 1 and 2 to make in converge faster; if the system is not guaranteed to converge setting it to a value between 0 and 1 may help keep things on track.

My implementation is by no means "bulletproof" but it should get you headed in the right direction. Hope it helps you.

PS if you have any questions about it please ask, and if you make any improvements to it I'd like to see them!
OK here's the code:

'10/15/2001
'Module to perform Gauss-Seidel algorithm
'to solve a system of linear equations

'as is, these functions expect 0 based arrays

Option Explicit

Public Function NormalizeSystem(Coefficients() As Double, Constants() As Double)
As Boolean

  Dim dblDummy As Double
  Dim i As Integer
  Dim j As Integer

  On Error GoTo ErrorNormalizeSystem

  For i = 0 To UBound(Coefficients(), 1)
    dblDummy = Coefficients(i, i)
    For j = 0 To UBound(Coefficients(), 2)
      Coefficients(i, j) = Coefficients(i, j) / dblDummy
    Next j
    Constants(i) = Constants(i) / dblDummy
  Next i

  NormalizeSystem = True
  Exit Function

ErrorNormalizeSystem:
  NormalizeSystem = False

End Function

Public Function GaussSeidel(Coefficients() As Double, _
      Constants() As Double, _
      Unknowns() As Double, _
      Optional ErrorAllow As Single = 0.001, _
      Optional MaxIterations As Integer = 100, _
      Optional RelaxCoeff As Single = 1) As Boolean

  Dim intIterations As Integer
  Dim blnSentinel As Boolean
  Dim dblError As Double
  Dim dblOld As Double
  Dim dblSum As Double
  Dim i As Integer, j As Integer

  NormalizeSystem(Coefficients(), Constants())

  If ErrorAllow <= 0 Then ErrorAllow = 0.0001
  If RelaxCoeff < 0 Then RelaxCoeff = 0
  If RelaxCoeff > 2 Then RelaxCoeff = 2

  intIterations = 0
  blnSentinel = False

  On Error GoTo ErrorGaussSeidel

  Do While (intIterations < MaxIterations) And (blnSentinel = False)
    'blnSentinel = True
    intIterations = intIterations + 1

    'loop through the equations
    For i = 0 To UBound(Coefficients(), 1)
      dblOld = Unknowns(i)
      dblSum = Constants(i)

      'loop through the coefficients in the equation
      For j = 0 To UBound(Coefficients(), 2)

        If i <> j Then
          dblSum = dblSum - Coefficients(i, j) * Unknowns(j)
        End If

      Next j

      Unknowns(i) = RelaxCoeff * dblSum + (1 - RelaxCoeff) * dblOld

      If (blnSentinel = False) And (Unknowns(i) <> 0) Then
        dblError = Abs((Unknowns(i) - dblOld) / Unknowns(i)) * 100
      End If

    Next i

    If dblError <= ErrorAllow Then
      blnSentinel = True
      GaussSeidel = True
    End If
  Loop

  Exit Function

ErrorGaussSeidel:
  GaussSeidel = False

End Function

Public Function GaussSeidelConverge(Coefficients() As Double) As Boolean

  Dim i As Integer, j As Integer
  Dim sum As Double

  For i = 0 To UBound(Coefficients(), 1)
    sum = 0
    For j = 0 To UBound(Coefficients(), 2)
      If i <> j Then
        sum = sum + Abs(Coefficients(i, j))
      End If
    Next j
    If sum > Abs(Coefficients(i, i)) Then
      GaussSeidelConverge = False
      Exit Function
    Else
      GaussSeidelConverge = True
    End If
  Next i

End Function

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close