MMULT function
PRO
The MMULT
function in Jspreadsheet Formulas Pro is a mathematical tool that returns the matrix product of two arrays. Essentially, it multiplies two matrices (arrays of numbers arranged in rows and columns) together. The result is a new matrix, where each cell is calculated as the sum of the multiplication of elements from the corresponding row and column in the original matrices. This function is beneficial in various data analysis tasks, especially when dealing with large sets of data.
Documentation
Returns the matrix product of two arrays.
Category
Math and trigonometry
Syntax
MMULT(array1, array2)
Parameter | Description |
---|---|
array1 |
The first array or range to multiply. The number of columns in the first array must be the same as the number of rows in the second array. |
array2 |
The second array or range to multiply. The number of rows in the second array must be the same as the number of columns in the first array. |
Behavior
The MMULT
function is used to calculate the matrix product of two matrices. It multiplies two matrices together and returns the resulting matrix. Here are some of the expected behaviors of MMULT
:
MMULT
requires two arrays or ranges of numbers as input. It will not work with text or boolean values.- Both matrices should have dimensions that are compatible for multiplication. The number of columns in the first matrix must be equal to the number of rows in the second matrix.
- If there are empty cells in the matrices,
MMULT
treats these cells as zeroes. - If there are non-numeric values (like text or boolean values) in the matrices,
MMULT
will return an error. - If any of the input cells contain errors,
MMULT
will return an error. - The result of
MMULT
is an array with the same number of rows as the first matrix and the same number of columns as the second matrix.
Common Errors
Error | Description |
---|---|
#VALUE! | This error occurs when the two input arrays have incompatible dimensions for multiplication, or if any of the cells in the arrays contain non-numeric values. |
#N/A | This error occurs when the arrays cannot return a valid result, often due to incorrect output placement or incomplete references. |
#REF! | Returned when the result cannot fit in the selected output range. |
#NUM! | This error occurs when the calculation exceeds the maximum limit for numbers. |
Best practices
- Make sure that the dimensions of the two matrices are compatible for multiplication. The number of columns in the first matrix should be equal to the number of rows in the second matrix.
- Check your data for non-numeric values before using MMULT. If any cells contain text, boolean values, or errors, MMULT will return an error.
- Remember that MMULT treats empty cells as zeroes. If this is not your intended behavior, you might need to clean up your data before using MMULT.
- Keep in mind that the resulting array from MMULT will have the same number of rows as the first matrix and the same number of columns as the second matrix. Make sure there is enough space in your spreadsheet to display the result.
Usage
A few examples using the MMULT function.
MMULT(A1:C3, D1:F3)
// Returns the matrix product of the two ranges, producing a new 3x3 matrix.
MMULT(A1:C2, D1:E3)
// Produces a 2x2 matrix as the result, since dimensions are compatible.
Interactive Spreadsheet Demo
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YTc4OGU1NDk2NzY4MDE2YzVlZjVjMTAyMDRkNDhkMzdiOTlmNjJmZjhlMjQ4YjBjYzU5Nzg4OTE1NzM3MTE1OWY2ZTllNjI2ZGU0ZDczNGZjOWU1ZTczYzE0MjdmNGJkNTUzNTU0NDU5MDE1YzFiOGI5MTdmOWY1NzI1ZjI1YjUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVMk56a3pNRGMxTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: [
[
2,
3,
1,
4,
2
],
[
1,
4,
2,
3,
1
],
[
3,
2,
4,
1,
3
],
[],
[
"=MMULT(A1:C3,D1:E3)",
"Matrix Product"
]
]
}]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
// Set license
jspreadsheet.setLicense('YTc4OGU1NDk2NzY4MDE2YzVlZjVjMTAyMDRkNDhkMzdiOTlmNjJmZjhlMjQ4YjBjYzU5Nzg4OTE1NzM3MTE1OWY2ZTllNjI2ZGU0ZDczNGZjOWU1ZTczYzE0MjdmNGJkNTUzNTU0NDU5MDE1YzFiOGI5MTdmOWY1NzI1ZjI1YjUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVMk56a3pNRGMxTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Worksheet data
const data = [
[
2,
3,
1,
4,
2
],
[
1,
4,
2,
3,
1
],
[
3,
2,
4,
1,
3
],
[],
[
"=MMULT(A1:C3,D1:E3)",
"Matrix Product"
]
];
// Render component
return (
<Spreadsheet ref={spreadsheet}>
<Worksheet data={data} />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet">
<Worksheet :data="data" />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";
// Set license
jspreadsheet.setLicense('YTc4OGU1NDk2NzY4MDE2YzVlZjVjMTAyMDRkNDhkMzdiOTlmNjJmZjhlMjQ4YjBjYzU5Nzg4OTE1NzM3MTE1OWY2ZTllNjI2ZGU0ZDczNGZjOWU1ZTczYzE0MjdmNGJkNTUzNTU0NDU5MDE1YzFiOGI5MTdmOWY1NzI1ZjI1YjUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVMk56a3pNRGMxTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
// Worksheet data
const data = [
[
2,
3,
1,
4,
2
],
[
1,
4,
2,
3,
1
],
[
3,
2,
4,
1,
3
],
[],
[
"=MMULT(A1:C3,D1:E3)",
"Matrix Product"
]
]
return {
data
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YTc4OGU1NDk2NzY4MDE2YzVlZjVjMTAyMDRkNDhkMzdiOTlmNjJmZjhlMjQ4YjBjYzU5Nzg4OTE1NzM3MTE1OWY2ZTllNjI2ZGU0ZDczNGZjOWU1ZTczYzE0MjdmNGJkNTUzNTU0NDU5MDE1YzFiOGI5MTdmOWY1NzI1ZjI1YjUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVMk56a3pNRGMxTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: [
[
2,
3,
1,
4,
2
],
[
1,
4,
2,
3,
1
],
[
3,
2,
4,
1,
3
],
[],
[
"=MMULT(A1:C3,D1:E3)",
"Matrix Product"
]
]
}]
});
}
}