Community discussion forum

urgent - Matrix Multiplication vb.net

Tags:
  • 1 year ago

    It sounds like you need to use a multidimensional array:

    To calculate these values, you need to run some form of control of flow statement:

    Dim arr(,) As Integer = New Integer(1, 1) {}

    arr(0, 0) = 1

    arr(0, 1) = 2

    arr(1, 0) = 3

    arr(1, 1) = 4

    For i As Integer = 0 To arr.GetUpperBound(0)For j As Integer = 0 To arr.GetUpperBound(0)

    ... do work here...

    Next

    Next

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 1 year ago

    Look, if you can't figure out how to get runtime values into the array, you really should not be programming.

  • 1 year ago

    Maybe you try a very easy way to solve your problem first:

    - Create 8 textboxes, the first four textboxes represent the first matrix, the second four textboxes represent the second matrix.

    - Create 4 labels, they represent the resulting matrix.

    - Create a button. When the button is pressed, just do your math and fill the labels with the result.

    Now save your project and create a new one.

    - Create 18 textboxes, each group of nine textboxes represents a matrix.

    - Create 9 labels, they represent the resulting matrix.

    - Create the button. Update the math routine.

    When everything is working fine, change the first matrix to a 2-dimensional array.

    When everything is working fine again, change the second and the resulting matrix to a 2-dimensional array.

     

    It will be a lot of work and may be overkill for such a small program but this kind of "evolutionary" software design usually makes it easy to understand every small step and results in a huge understanding of the big step.

  • 0 month ago

    No babu, I said if you cannot get the runtime values into the array you should not be programming; equally I noted you post on Tuesday asking how to get the runtime values into a multi-dimensional array. Also babu, why, if you a learning vb,do you use urgent when submitting a post; this often puts people off from reading the post.

  • 11 months ago

    Hei Babu,
                   Create a form and  place a textbox then paste these codes into its code window

    form name =form1
    textbox name=textbox1
         try it ,i think you shall get your expectaion result
    --------------------------- 

    Public
    Class Form1

    Public M, N As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Width = 350

    Me.Height = 350

    TextBox1.Multiline = True

    TextBox1.Width = 300

    TextBox1.Height = 300

    Dim M1, M2, N1, N2, i, j, k As Integer

    Dim a(10, 10), b(10, 10), c(10, 10) As Integer 'for two dimensional array

    MsgBox("Get order of first M X N matrix")

    'for reading order of the first matrix

    getorderofmatrix()

    M1 = M

    N1 = N

    MsgBox(
    "Enter Elements")

    k = 1

    For i = 0 To M1 - 1

    For j = 0 To N1 - 1

    a(i, j) = InputBox("Enter the" & k & "-th Element")

    k = k + 1

    Next

    Next

    'for reading order of the 2nd first matrix

    MsgBox("Get order of Second M X N matrix ")

    getorderofmatrix()

    M2 = M

    N2 = N

    MsgBox(
    "Enter Elements")

    k = 1

    For i = 0 To M2 - 1

    For j = 0 To N2 - 1

    b(i, j) = InputBox("Enter the" & k & "-th Element")

    k = k + 1

    Next

    Next

    If N1 = M2 Then

    For i = 0 To M1 - 1For j = 0 To N2 - 1

    c(i, j) = 0

    For k = 0 To N1 - 1

    c(i, j) = c(i, j) + (a(i, k) * b(k, j))

    Next

    Next

    Next

    TextBox1.Text = " Matrix A="

    'for next line

    TextBox1.Text += vbCrLf

    For i = 0 To M1 - 1

    For j = 0 To N1 - 1

    TextBox1.Text += a(i, j) & " "

    Next

    TextBox1.Text += vbCrLf

    Next

    TextBox1.Text += vbCrLf

    TextBox1.Text += " Matrix B="

    TextBox1.Text += vbCrLf

    For i = 0 To M2 - 1

    For j = 0 To N2 - 1

    TextBox1.Text += b(i, j) & " "

    Next

    TextBox1.Text += vbCrLf

    Next

    TextBox1.Text += vbCrLf

    TextBox1.Text += " A X B ="

    TextBox1.Text += vbCrLf

    For i = 0 To M1 - 1

    For j = 0 To N2 - 1

    TextBox1.Text += c(i, j) & " "

    Next

    TextBox1.Text += vbCrLf

    Next

    Else

    MsgBox("cannot multyplay ")

    End If

    End Sub

    Public Function getorderofmatrix()

    M = InputBox(" M= ")

    N = InputBox(" N= ")

    End Function

    End Class

Post a reply

Enter your message below

Sign in or Join us (it's free).