Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* *##% NuitonMatrix
* Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* . ##%*/
package org.nuiton.math.matrix;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Stack;
/**
* Contains usefull methods to get information on matrix.
*
* Created: 28 oct. 2004
*
* @author Benjamin Poussin
* @version $Revision: 187 $
*
* Mise a jour: $Date: 2009-10-16 19:17:29 +0200 (ven., 16 oct. 2009) $
* par : $Author: tchemit $
*/
public class MatrixHelper { // MatrixHelper
/**
* Convert Matrix to identity matrix must have 2 dimensions. If dimension
* haven't same length, then the small dimension is used.
*
* @param mat matrix nd to convert
* @return converted matrix
*/
public static MatrixND convertToId(MatrixND mat) {
int size = mat.getDim(0);
if (size > mat.getDim(1)) {
size = mat.getDim(1);
}
fill(mat, 0);
for (int i = 0; i < size; i++) {
mat.setValue(i, i, 1);
}
return mat;
}
/**
* Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]]
*
* Remarque: une premiere implantantion avait ete faite en utilisant
* {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne sait pas
* parser les chiffres avec un exposant: 5.0E-7 par exemple est lu comme 5.0
* :(
*
* Remarque: une autre implantation de remplacement a ete faite en utilisant
* le {@link org.nuiton.util.StringUtil#split(String, String)} mais elle
* etait moins performante (x2)
*
* @param s la chaine representant les listes de liste
* @return une liste de liste ... de Double
*/
public static List> convertStringToList(String s) {
List