Subtracts a matrix from another matrix.
Syntax
| Visual Basic (Declaration) | |
|---|
Public Shared Function Subtract( _
ByVal A As Matrix, _
ByVal B As Matrix _
) As Matrix |
Parameters
- A
- A Matrix instance on the left side of the subtraction operator.
- B
- A Matrix instance on the right side of the subtraction operator.
Return Value
A
Matrix object that represents the result of the subtraction.
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 Matrix(4, 4), B As New Matrix(4, 4)
A.FillRandom()
B.FillRandom()
Console.WriteLine("Matrix A:")
Console.WriteLine(A)
Console.WriteLine("Matrix B:")
Console.WriteLine(B)
'Matrix addition
Dim C As Matrix
'Performing matrix addition
C = Matrix.Add(A, B)
'this is the same as:
C = Matrix.op_Addition(A, B)
Console.WriteLine("C = A + B")
Console.WriteLine(C)
'Matrix subtraction
Dim D As Matrix
D = Matrix.Subtract(A, B)
'this is the same as:
D = Matrix.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
Matrix A = new Matrix(4, 4), B = new Matrix(4, 4);
A.FillRandom();
B.FillRandom();
Console.WriteLine("Matrix A:");
Console.WriteLine(A);
Console.WriteLine("Matrix B:");
Console.WriteLine(B);
//Matrix addition
Matrix C;
//Performing matrix addition
C = Matrix.Add(A, B);
//this is the same as:
C = A + B;
Console.WriteLine("C = A + B");
Console.WriteLine(C);
//Matrix subtraction
Matrix D;
D = Matrix.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;
int main(array<System::String ^> ^args)
{
//Declaring two 4x4 Matrices with random elements
Matrix ^A = gcnew Matrix(4, 4), ^B = gcnew Matrix(4, 4);
A->FillRandom();
B->FillRandom();
Console::WriteLine("Matrix A:");
Console::WriteLine(A);
Console::WriteLine("Matrix B:");
Console::WriteLine(B);
//Matrix addition
Matrix^ C;
//Performing matrix addition
C = Matrix::Add(A, B);
//this is the same as:
//C = A + B;
Console::WriteLine("C = A + B");
Console::WriteLine(C);
//Matrix subtraction
Matrix^ D;
D = Matrix::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