Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS5106

error The matrix sizes do not fit (detail).

#What it means

A matrix operation got matrices whose sizes do not fit together. The detail in brackets gives the sizes. For example, multiplying needs the first matrix to have as many columns as the second has rows.

#Typical cause

  • Multiplying two matrices with the same non-square shape.
  • An operation that needs a square matrix (such as the inverse) given a rectangular one.

#How to fix it

Check the shapes with rows() and columns(), or transpose one matrix first (transpose()). See Collections.

#Example

ChartScriptOpen in editor
//@chartscript 1
indicator("Matrix product")
const a = matrix.new<float>(2, 3, 1.0)
const b = matrix.new<float>(2, 3, 1.0)
const c = a.mult(b)
plot(c.rows())

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Matrix product")
const a = matrix.new<float>(2, 3, 1.0)
const b = matrix.new<float>(3, 2, 1.0)
const c = a.mult(b)
plot(c.rows())
  • CS5107 — name needs a square symmetric matrix in this version.
  • CS5101 — Index index is out of range (size size).

The ChartScript documentation is in English for now; translations will follow.