function minus
minus(
x: number,
y: number,
): number

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

number

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: number,
y: array,
): array

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: array,
y: number,
): array

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: array,
y: array,
): array

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: number,
y: matrix,
): matrix

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: matrix,
y: number,
): matrix

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

minus(
x: matrix,
y: matrix,
): matrix

Subtraction X - Y.

Subtracts two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Subtract two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus(5, 3), 2);

Subtract two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([5, 6, 4], [3, 1, 2]), [2, 5, 2]);

Subtract a number from each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([15, 16, 14], 10), [5, 6, 4]);

Subtract a number from each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[15, 16], [13, 14]], 10), [[5, 6], [3, 4]]);

Subtract two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(minus([[7, 9], [4, 6]], [[2, 3], [1, 2]]), [[5, 6], [3, 4]]);

Parameters

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of subtracting y from x.

Throws

If the input dimensions do not agree or if no arguments are provided.

Usage

import minus from "elemop/minus.ts";