Adds two matrices.
Syntax
Parameters
- A
- A CMatrix instance on the left side of the addition operator.
- B
- A CMatrix instance on the right side of the addition operator.
Return Value
A
CMatrix object that represents the result of the addition.
Exceptions
Example
The following example uses the
Add and
Subtract methods to perform matrix addition and subtraction.
| Visual Basic | Copy Code |
|---|
Imports System
Imports Bluebit.MatrixLibrary
Class Test
Public Shared Sub Main()
'Declaring two 4x4 Matrices with random elements
Dim A As New CMatrix(4, 4), B As New CMatrix(4, 4)
A.FillRandom()
B.FillRandom()
Console.WriteLine("CMatrix A:")
Console.WriteLine(A)
Console.WriteLine("CMatrix B:")
Console.WriteLine(B)
'Matrix addition
Dim C As CMatrix
'Performing matrix addition
C = CMatrix.Add(A, B)
'this is the same as:
C = CMatrix.op_Addition(A, B)
Console.WriteLine("C = A + B")
Console.WriteLine(C)
'Matrix subtraction
Dim D As CMatrix
D = CMatrix.Subtract(A, B)
'this is the same as:
D = CMatrix.op_Subtraction(A, B)
Console.WriteLine("D = A - B")
Console.WriteLine(D)
Console.Read()
End Sub
End Class
|
| C# | Copy Code |
|---|
using System;
using Bluebit.MatrixLibrary;
class Test
{
static void Main(string[] args)
{
//Declaring two 4x4 Matrices with random elements
CMatrix A = new CMatrix(4, 4), B = new CMatrix(4, 4);
A.FillRandom();
B.FillRandom();
Console.WriteLine("CMatrix A:");
Console.WriteLine(A);
Console.WriteLine("CMatrix B:");
Console.WriteLine(B);
//Matrix addition
CMatrix C;
//Performing matrix addition
C = CMatrix.Add(A, B);
//this is the same as:
C = A + B;
Console.WriteLine("C = A + B");
Console.WriteLine(C);
//Matrix subtraction
CMatrix D;
D = CMatrix.Subtract(A, B);
//this is the same as:
D = A - B;
Console.WriteLine("D = A - B");
Console.WriteLine(D);
Console.Read();
}
}
|
| C++ | Copy Code |
|---|
#include "stdafx.h"
using namespace System;
using namespace Bluebit::MatrixLibrary;
using namespace System::Numerics;
int main(array<System::String ^> ^args)
{
//Declaring two 4x4 Matrices with random elements
CMatrix ^A = gcnew CMatrix(4, 4), ^B = gcnew CMatrix(4, 4);
A->FillRandom();
B->FillRandom();
Console::WriteLine("CMatrix A:");
Console::WriteLine(A);
Console::WriteLine("CMatrix B:");
Console::WriteLine(B);
//Matrix addition
CMatrix^ C;
//Performing matrix addition
C = CMatrix::Add(A, B);
//this is the same as:
C = A + B;
Console::WriteLine("C = A + B");
Console::WriteLine(C);
//Matrix subtraction
CMatrix^ D;
D = CMatrix::Subtract(A, B);
//this is the same as:
D = A - B;
Console::WriteLine("D = A - B");
Console::WriteLine(D);
Console::Read();
return 0;
}
|
Remarks
Requirements
Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7
See Also