matrix/add

matrix/add

A library for adding a scalar/array/matrix to a scalar/array/matrix. This library will always return matrix type.

Methods

(static) add(x) → {matrix}

Source:

Add a scalar/array/matrix to self

Examples
// Add a scalar to a matrix
var M = require('./src/matrix_lib'); // or require('math-script')
var A = M.zeros(2,2); // Create 2x2 matrix of zeros
A = A.add(1); // Add scalar
console.log(A.print())
//Result 
//1.000           1.000
//1.000           1.000

// Add a matrix to a matrix
var B = M.ident(2,2).add(A) // Add "A" to a 2x2 identity matrix
console.log(B.print())
//Result
//2.000           1.000
//1.000           2.000
// Use add in execute environment  
var M = require('./src/matrix_lib'); // or require('math-script')
M.execute(function(M){

var A = M.make([[1,2],[3,4]]); // Create a 2x2 matrix
var B = A + A + 1; // Add matrices and scalars together 
console.log(B.print())

});
//Result
//3.000           5.000
//7.000           9.000
Parameters:
Name Type Description
x scalar/array/matrix

Adds a scalar/array/matrix to self

Returns:
Type
matrix

(static) subtract(x) → {matrix}

Source:

Subtract a scalar/array/matrix to self

Parameters:
Name Type Description
x scalar/array/matrix

Adds a scalar/array/matrix to self

Returns:
Type
matrix