Mercurial > hg > jslab
view src/samer/units/Matrices.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.units; import samer.core.*; import samer.maths.*; /** Some special matrix factories */ public class Matrices { public static void set(Matrix A, Generator G) { A.set(G); A.changed(); } public static void add(Matrix A, Generator G) { A.add(G); A.changed(); } public static void fourierBasis(Matrix A) { int m=A.getColumnDimension(); int n=A.getRowDimension(); double [][] a = A.getArray(); for (int j=3; j<m;j+=2) { double omega=(j-1)*Math.PI/m; for (int i=0; i<n; i++) { double theta=i*omega; a[i][j-2] = Math.cos(theta); a[i][j-1] = Math.sin(theta); } } for (int i=0; i<n; i++) { a[i][0] = 1; a[i][m-1] = (i%2)==0 ? 1 : -1; } A.changed(); } public static void pingBasis(Matrix A) { pingBasis(A,Shell.getDouble("gamma",0.5)); } public static void pingBasis(Matrix A, double gamma) { int extra = (int)(3.0*16.0/gamma); int m=A.getColumnDimension(); int n=A.getRowDimension(); double [][] a = A.getArray(); A.zero(); for (int j=0; j<m; j++) { int jj=(int)((n+extra)*Math.random())-extra; double omega=0.2+2*Math.random(); double t=0.0; for (int i=0; i<n; i++) { if (i>=jj) { t=i-jj; a[i][j]=Math.exp(-gamma*t/16)*Math.sin(omega*t); } else a[i][j]=0; } } A.changed(); } public static void fuzzyIdentity(Matrix matrix) { int n = matrix.getRowDimension(); int m = matrix.getColumnDimension(); fuzzyIdentity(matrix,Shell.getDouble("sigma", (n>m) ? n/(double)m : m/(double)n)); } public static void fuzzyIdentity(Matrix matrix, double s) { int n = matrix.getRowDimension(); int m = matrix.getColumnDimension(); double t = s/Math.max(n,m); double I[][] = matrix.getArray(); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { double Z = j/(double)(m-1) - i/(double)(n-1); I[i][j] = Math.exp(-(Z*Z)/(2*t*t)); } } matrix.changed(); } }