DEV Community

Cover image for Create a 2x2, 3x3 or NxN matrix with JS
Valentin Antonio
Valentin Antonio

Posted on

2 2

Create a 2x2, 3x3 or NxN matrix with JS

The matrix 2x2 is simple, :
I think the matrix of 2x2 and 3x3 is easy.

Example: Matrix [2x2];

var det=(matriz[0][0]*matriz[1][1])-(matriz[1][0]*matriz[0][1]);

Example: Matrix [3x3];

var r1=(matriz[0][0]*matriz[1][1]*matriz[2][2])+(matriz[0][1]*matriz[1][2]*matriz[2][0])+(matriz[0][2]*matriz[1][0]*matriz[2][1]);
var r2=(matriz[0][2]*matriz[1][1]*matriz[2][0])+(matriz[0][0]*matriz[1][2]*matriz[2][1])+(matriz[0][1]*matriz[1][0]*matriz[2][2]);
var result = r1-r2;

First create a function for get size the matrix.

 function Matriz(size){
     var matriz = new Array(size);
         for(i = 0; i < size ; i++){
                matriz[i]=new Array(size);

          }
     return matriz;
 }

to be continue

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️