/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.math.matrix"); // some of this code is based on // http://www.mkaz.com/math/MatrixCalculator.java // (published under a BSD Open Source License) // // the rest is from my vague memory of matricies in school [cal] // // the copying of arguments is a little excessive, and could be trimmed back in // the case where a function doesn't modify them at all (but some do!) // // 2006-06-25: Some enhancements submitted by Erel Segal: // * addition: a tolerance constant for determinant calculations. // * performance fix: removed unnecessary argument copying. // * addition: function "product" for multiplying more than 2 matrices // * addition: function "sum" for adding any number of matrices // * bug fix: inversion of a 1x1 matrix without using the adjoint // * performance fixes: upperTriangle // * addition: argument "value" to function create, to initialize the matrix with a custom val // * addition: functions "ones" and "zeros" - like Matlab[TM] functions with the same name. // * addition: function "identity" for creating an identity matrix of a given size. // * addition: argument "decimal_points" to function format // * bug fix: adjoint of a 0-size matrix // * performance fixes: adjoint // dojo.math.matrix.iDF = 0; // Erel: values lower than this value are considered zero (in detereminant calculations). // It is analogous to Maltab[TM]'s "eps". dojo.math.matrix.ALMOST_ZERO = 1e-10; dojo.math.matrix.multiply = function(a, b){ var ay = a.length; var ax = a[0].length; var by = b.length; var bx = b[0].length; if (ax != by){ dojo.debug("Can't multiply matricies of sizes "+ax+','+ay+' and '+bx+','+by); return [[0]]; } var c = []; for(var k=0; k0? a[0].length: 0; var buffer = ''; for (var y=0; y