this is the code for my class for matrix multiplication.
but i am not getting the required result of multiplication
getting error as "Number of indices exceeds the number of dimensions of the indexed array"
please help me to solve this problem...
thaking you.....

Public Class complexnum

    Private x As Double
    Private y As Double
       Private matrixA As Double
    Private matrixB As Double
    Private e, f, g As Integer
    Public Property Real() As Double
            Return x
        End Get
        Set(ByVal Value As Double)
            x = Value
        End Set
    End Property
    Public Property Imaginary() As Double
            Return y
        End Get
        Set(ByVal Value As Double)
            y = Value
        End Set
    End Property

    Public Sub New(Optional ByVal real As Double = 0.0, Optional ByVal imaginary As Double = 0.0)
        x = real
        y = imaginary
    End Sub
         Public Function multiplication() As complexnum
        Dim row1() As Double
        Dim row2() As Double
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim tmprow1 As Double
        Dim tmprow2 As Double

        For i = 0 To e - 1
            For j = 0 To f - 1
                For k = 0 To g - 1

                    Dim result(i, j) As Double
                    result(i, j) = result(i, j) + (row1(i, k) * row2(k, j))

    End Function
    Public Overrides Function ToString() As String
        Dim result As String = x.ToString()
        If y >= 0 Then
            result &= " + " & _
                y.ToString() & _
            result &= " - " & _
                (-y).ToString() & _
        End If

        Return result
    End Function
End Class
4 Years
Discussion Span
Last Post by arizan

You have 3 arrays (row1, row2, result) I only see you giving one of these arrays any dimensions (result) and you are recreating and so wiping out your result array each time.

Also, I see you are using integers e, f, g, i, j, k etc. but I don't see where these values are set.... You may just not be putting it in the sample.

Anyway one thing at a time, in order to use an array you must give it dimensions to store the data in for example say I had an array made up of fruit and the quantity of each I could do this:

dim FruitStock(3,1) as object

Fruitstock(0,0) = "Apple"
FruitStock(0,1) = 2
Fruitstock(1,0) = "Pear"
FruitStock(1,1) = 3
FruitStock(2,0) = "Orange"
FruitStock(2,1) = 1
Fruitstock(3,0) = "Banana"
FruitStock(3,1) =2

As you can see in VB.net arrays are zero based and can have multiple dimensions

"OK" I hear you cry, "I don't know how much fruit I have"

This is where you use a dynamic array...

'You can not increase the number of dimensions dynamically in an array
'You may only increase the size of the outer most dimension dynamically
dim FruitStock(1,0)  

'say we get values in from a query:

While MyReader.Read
'Resize and KEEP our values
    Redim Preserve FruitStock(2, ubound(FruitStock,2)+1)
'ubound = upper boundary of array , 2 second dimension Preserve = keep values
 FruitStock(0,i) = MyReader("Fruit")
 FruitStock(1,i) = MyReader("Amount")
While End

hey thanx but i am new in vb.net coding so m getting some problems in coding
i am entering thr values by using following form
please help me please

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       'Matrix1 values are inputed
        ar1.Real = Val(ar1txt.Text)
        ai1.Imaginary = Val(ai1txt.Text)
        ar2.Real = Val(ar2txt.Text)
        ai2.Imaginary = Val(ai2txt.Text)
        ar3.Real = Val(ar3txt.Text)
        ai3.Imaginary = Val(ai3txt.Text)
        ar4.Real = Val(ar4txt.Text)
        ai4.Imaginary = Val(ai4txt.Text)

      'Matrix2 values are inputed
        br1.Real = Val(br1txt.Text)
        bi1.Imaginary = Val(bi1txt.Text)
        br2.Real = Val(br2txt.Text)
        bi2.Imaginary = Val(bi2txt.Text)
        br3.Real = Val(br3txt.Text)
        bi3.Imaginary = Val(bi3txt.Text)
        br4.Real = Val(br4txt.Text)
        bi4.Imaginary = Val(bi4txt.Text)

     'output of complex matrix

        cr1 = cr1.multiplication(ar1, bi1)
        ans1txt.Text = cr1.Real & "+i" & cr1.Imaginary

        cr2 = cr2.multiplication(ar2, bi2)
        ans2txt.Text = cr2.Real & "+i" & cr2.Imaginary

        cr3 = cr3.multiplication(ar3, bi3)
        ans3txt.Text = cr3.Real & "+i" & cr3.Imaginary

        cr4 = cr4.multiplication(ar4, bi4)
        ans4txt.Text = cr4.Real & "+i" & cr4.Imaginary
    End Sub
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.