.NET Matrix Library
Add Method
See Also  Example Send Feedback



A
A CMatrix instance on the left side of the addition operator.
B
A CMatrix instance on the right side of the addition operator.
Adds two matrices.

Syntax

Visual Basic (Declaration) 
Public Shared Function Add( _
   ByVal A As CMatrix, _
   ByVal B As CMatrix _
) As CMatrix
Visual Basic (Usage)Copy Code
Dim A As CMatrix
Dim B As CMatrix
Dim value As CMatrix
 
value = CMatrix.Add(A, B)
C# 
public static CMatrix Add( 
   CMatrix A,
   CMatrix B
)
C++/CLI 
public:
static CMatrix^ Add( 
   CMatrix^ A,
   CMatrix^ B
) 

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

ExceptionDescription
SizeMismatchExceptionA, B are not of the same size.

Example

The following example uses the Add and Subtract methods to perform matrix addition and subtraction.
Visual BasicCopy 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

The Add method is an alias for the Addition operator.

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

.NET Matrix Library