Click here to Skip to main content
15,906,094 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
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
        Get
            Return x
        End Get
        Set(ByVal Value As Double)
            x = Value
        End Set
    End Property
    Public Property Imaginary() As Double
        Get
            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))
                Next
            Next
        Next

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

        Return result
    End Function
End Class


here is the form in which the values are inputed and getting output
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
Posted
Updated 9-Jul-12 18:15pm
v3
Comments
bbirajdar 9-Jul-12 5:08am    
which line of code gives this error?
Sanjay Kunjam 9-Jul-12 5:16am    
What is the value of e,f and g?
arizan 9-Jul-12 5:27am    
result(i, j) = result(i, j) + (row1(i, k) * row2(k, j))
this line s having error...

There are many errors in your code, for instance, you never allocate memory for the row1, row2 arrays.
 
Share this answer
 
Comments
arizan 9-Jul-12 5:29am    
actually i am new in vb.net code so not getting the code...
please tell want changes i should make...
thanking you....
you trying to access the array variables row1() and row2() without defining there size and values.

as CPallini has stated you need to assign data to these arrays so that you can use their values in your calculation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900