m * n矩阵的加法..... [英] addtion of m*n matrix.....
问题描述
hiiiiii
我在开发用于添加3x3矩阵类的代码时遇到一些问题
我开发的代码如下.
但是此类不在vb.net代码中执行.
不知道发生了什么错误,因为无法获得所需的结果.
请帮助我更正vb.net中m的代码...
hiiiiii
i have some problem for developing the code for addtion of 3x3 matrix class
the code which i have develop is given below.
but this class is not executed in vb.net code.
dont know whats getting wrong in it as m nt getting the required result.
please help me in correcting the code as m new in vb.net...
Public Class Matrix3x3
Private m_values(8) As Integer
Sub New()
' initialise array:
m_values = New Integer(8) {}
End Sub
' expose a member of the array:
Public Property Item(ByVal index As Integer) As Integer
Get
If index < 0 Or index > 8 Then Throw New ArgumentOutOfRangeException
Return m_values(index)
End Get
Set(ByVal value As Integer)
If index < 0 Or index > 8 Then Throw New ArgumentOutOfRangeException
m_values(index) = value
End Set
End Property
' allow get/set by row/column
Public Property Item(ByVal row As Integer, ByVal column As Integer) As Integer
Get
If row < 0 Or row > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
If column < 0 Or column > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
Dim index As Integer = (row * 3) + column
Return m_values(index)
End Get
Set(ByVal value As Integer)
If row < 0 Or row > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
If column < 0 Or column > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
Dim index As Integer = (row * 3) + column
m_values(index) = value
End Set
End Property
Public Function Add(ByVal matrixToAdd As Matrix3x3) As Matrix3x3
' declare a matrix to hold the result
Dim result As New Matrix3x3
' loop through arrays and the members of the two matrixes, store in the result matrix
For i As Integer = 0 To 8
result.Item(i) = m_values(i) + matrixToAdd.Item(i)
Next
Return result
End Function
Public Overrides Function ToString() As String
Dim msg As New System.Text.StringBuilder
' find the longest value when represented as string
Dim longest As Integer = -1
For i As Integer = 0 To 8
If m_values(i).ToString.Length > longest Then longest = m_values(i).ToString.Length
Next
' create the string
longest += 1
Dim width As String = longest.ToString
For y As Integer = 0 To 2
For x As Integer = 0 To 2
msg.Append(String.Format("{0," & width & "}", m_values((y * 3) + x)))
Next
msg.Append(Environment.NewLine)
Next
Return msg.ToString
End Function
End Class
这是vb.net代码
this is vb.net code
Public Class Form1
Dim a1 As New Matrix3x3
Dim b1 As New Matrix3x3
Dim c1 As New Matrix3x3
Dim rand As New Random
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m As New Matrix3x3
Dim n As New Matrix3x3
For row As Integer = 0 To 2
For col As Integer = 0 To 2
row = TextBox2.Text
col = TextBox3.Text
m.Item(row, col) = ((row * 3) + col)
n.Item(row, col) = rand.Next(0, 2000)
a1 = a1.Add(n)
add1txt.Text=a1.ToString
Next
Next
End Sub
我想要文本框中的结果,其中输入是在文本框中手动给出的...
这里m,n是矩阵的行和列...
请帮助
提前thanx
I want the result in textboxes where the inputs are given in textboxes manually...
here m,n are the rows and columns of matrix...
please help
thanx in advance
推荐答案
请参考类似的线程:
VB.NET应用程序中的矩阵代数 [
Please refer similar thread:
matrix algebra in VB.NET application[^]
这篇关于m * n矩阵的加法.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!