List of usage examples for org.apache.commons.math3.linear RealMatrix getEntry
double getEntry(int row, int column) throws OutOfRangeException;
From source file:lambertmrev.LambertMRev.java
/** * @param args the command line arguments *///from w w w . j av a 2 s. c om public static void main(String[] args) { // Want to test the Lambert class so you can specify the number of revs for which to compute //System.out.print("this is the frames tutorial \n"); try { Frame inertialFrame = FramesFactory.getEME2000(); TimeScale utc = TimeScalesFactory.getTAI(); AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc); double mu = 3.986004415e+14; double a = 24396159; // semi major axis in meters double e = 0.72831215; // eccentricity double i = Math.toRadians(7); // inclination double omega = Math.toRadians(180); // perigee argument double raan = Math.toRadians(261); // right ascension of ascending node double lM = 0; // mean anomaly Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu); //KeplerianPropagator kepler = new KeplerianPropagator(initialOrbit); // set geocentric positions Vector3D r1 = new Vector3D(-6.88999e3, 3.92763e4, 2.67053e3); Vector3D r2 = new Vector3D(-3.41458e4, 2.05328e4, 3.44315e3); Vector3D r1_site = new Vector3D(4.72599e3, 1.26633e3, 4.07799e3); Vector3D r2_site = new Vector3D(4.70819e3, 1.33099e3, 4.07799e3); // get the topocentric positions Vector3D top1 = Transform.geo2radec(r1.scalarMultiply(1000), r1_site.scalarMultiply(1000)); Vector3D top2 = Transform.geo2radec(r2.scalarMultiply(1000), r2_site.scalarMultiply(1000)); // time of flight in seconds double tof = 3 * 3600; // propagate to 0 and tof Lambert test = new Lambert(); boolean cw = false; int multi_revs = 1; RealMatrix v1_mat; Random randomGenerator = new Random(); PrintWriter out_a = new PrintWriter("out_java_a.txt"); PrintWriter out_e = new PrintWriter("out_java_e.txt"); PrintWriter out_rho1 = new PrintWriter("out_java_rho1.txt"); PrintWriter out_rho2 = new PrintWriter("out_java_rho2.txt"); // start the loop double A, Ecc, rho1, rho2, tof_hyp; long time1 = System.nanoTime(); for (int ll = 0; ll < 1e6; ll++) { rho1 = top1.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top1.getZ() / 1000; rho2 = top2.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top2.getZ() / 1000; //tof_hyp = FastMath.abs(tof + 0.1*3600 * randomGenerator.nextGaussian()); // from topo to geo Vector3D r1_hyp = Transform.radec2geo(top1.getX(), top1.getY(), rho1, r1_site); Vector3D r2_hyp = Transform.radec2geo(top2.getX(), top2.getY(), rho2, r2_site); // System.out.println(r1_hyp.scalarMultiply(1000).getNorm()); // System.out.println(r2_hyp.scalarMultiply(1000).getNorm()); // System.out.println(tof/3600); test.lambert_problem(r1_hyp.scalarMultiply(1000), r2_hyp.scalarMultiply(1000), tof, mu, cw, multi_revs); v1_mat = test.get_v1(); Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2)); // System.out.println(v1); PVCoordinates rv1 = new PVCoordinates(r1_hyp.scalarMultiply(1000), v1); Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu); A = orbit_out.getA(); Ecc = orbit_out.getE(); // System.out.println(ll + " - " +A); out_a.println(A); out_e.println(Ecc); out_rho1.println(rho1); out_rho2.println(rho2); } long time2 = System.nanoTime(); long timeTaken = time2 - time1; out_a.close(); out_e.close(); out_rho1.close(); out_rho2.close(); System.out.println("Time taken " + timeTaken / 1000 / 1000 + " milli secs"); // get the truth test.lambert_problem(r1.scalarMultiply(1000), r2.scalarMultiply(1000), tof, mu, cw, multi_revs); v1_mat = test.get_v1(); Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2)); PVCoordinates rv1 = new PVCoordinates(r1.scalarMultiply(1000), v1); Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu); //System.out.println(orbit_out.getA()); } catch (FileNotFoundException ex) { Logger.getLogger(LambertMRev.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:lsafunctions.LSA.java
private static int calcDf(int nRow, RealMatrix M) { int df = 0;//from www . ja v a 2s . c om for (int j = 0; j < M.getColumnDimension(); j++) { if (M.getEntry(nRow, j) != 0) { df++; } } return df; }
From source file:com.analog.lyric.math.LyricSingularValueDecomposition.java
private static RealMatrix checkMatrix(RealMatrix m) { for (int i = 0; i < m.getRowDimension(); i++) { for (int j = 0; j < m.getColumnDimension(); j++) { if (Double.isNaN(m.getEntry(i, j)) || Double.isInfinite(m.getEntry(i, j))) { throw new DimpleException("cannot do SVD on matrix that contains NaN or infinite"); }//www . java 2 s.c o m } } return m; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.Ecef2EnuConverter.java
/** * Converts a vector represented by coordinates ecefX, ecefY, ecefZ in an * Earth-Centered Earth-Fixed (ECEF) Cartesian system into a vector in a * local east-north-up (ENU) Cartesian system. * * <p> For example it can be used to rotate a speed vector or position offset vector to ENU. * * @param ecefX X coordinates in ECEF//from w ww .j av a 2 s .c o m * @param ecefY Y coordinates in ECEF * @param ecefZ Z coordinates in ECEF * @param refLat Latitude in Radians of the Reference Position * @param refLng Longitude in Radians of the Reference Position * @return the converted values in {@code EnuValues} */ public static EnuValues convertEcefToEnu(double ecefX, double ecefY, double ecefZ, double refLat, double refLng) { RealMatrix rotationMatrix = getRotationMatrix(refLat, refLng); RealMatrix ecefCoordinates = new Array2DRowRealMatrix(new double[] { ecefX, ecefY, ecefZ }); RealMatrix enuResult = rotationMatrix.multiply(ecefCoordinates); return new EnuValues(enuResult.getEntry(0, 0), enuResult.getEntry(1, 0), enuResult.getEntry(2, 0)); }
From source file:edu.oregonstate.eecs.mcplan.ml.HilbertSpace.java
public static double inner_prod(final double[] x, final RealMatrix M, final double[] y) { double s = 0.0; for (int i = 0; i < M.getRowDimension(); ++i) { for (int j = 0; j < M.getColumnDimension(); ++j) { s += x[i] * M.getEntry(i, j) * y[j]; }// w w w . j a va 2 s.c o m } return s; }
From source file:com.itemanalysis.psychometrics.factoranalysis.MatrixUtils.java
public static double sumMatrix(RealMatrix X) { double sum = 0.0; for (int i = 0; i < X.getRowDimension(); i++) { for (int j = 0; j < X.getColumnDimension(); j++) { sum += X.getEntry(i, j); }/*from ww w.ja v a 2 s . c o m*/ } return sum; }
From source file:lambertmrev.conversions.java
public static CartesianOrbit hyp2ele(double[] hyp, Vector<Tracklet> subSet, constraints set, TopocentricFrame staF, Frame inertialFrame, TimeScale utc) { int N = subSet.size(); AbsoluteDate year = new AbsoluteDate(Main.YEAR, utc); double tof = FastMath.abs(subSet.elementAt(0).getDOY() - subSet.elementAt(N - 1).getDOY()) * 24 * 3600; // System.out.println("RA\t:" + subSet.elementAt(0).getRA() + "\tDEC:\t" + subSet.elementAt(0).getDEC() + "\thyp:\t" + hyp[0]); Vector3D geoPos1 = conversions.radec2geo(subSet.elementAt(0), hyp[0], staF, inertialFrame, utc); Vector3D geoPos2 = conversions.radec2geo(subSet.elementAt(N - 1), hyp[1], staF, inertialFrame, utc); // System.out.println("x1:\t" + geoPos1.getX() + "\ty1:\t" + geoPos1.getY() + "\tz1:\t" + geoPos1.getZ()); // define epoch of first tracklet AbsoluteDate epoch0 = new AbsoluteDate(year, subSet.elementAt(0).getDOY() * 24 * 3600); // perform lambert solver Lambert solve = new Lambert(); solve.lambert_problem(geoPos1, geoPos2, tof, Constants.EIGEN5C_EARTH_MU, Boolean.FALSE, 1); RealMatrix v1 = solve.get_v1(); // get the orbital elements at epoch 0 Vector3D v1vec = new Vector3D(v1.getEntry(0, 0), v1.getEntry(0, 1), v1.getEntry(0, 2)); PVCoordinates PVgeo1 = new PVCoordinates(geoPos1, v1vec); CartesianOrbit orbit = new CartesianOrbit(PVgeo1, inertialFrame, epoch0, Constants.EIGEN5C_EARTH_MU); // System.out.println("a:\t" + orbit.getA() + "\ti:\t" + orbit.getI() + "\te:\t" + orbit.getE()); return orbit; }
From source file:lsafunctions.LSA.java
public static double cosinSim(int v1, int v2, RealMatrix Vt) { double sim = 0.0; double sumNum = 0.0; double fdenom = 0.0; double sdenom = 0.0; for (int j = 0; j < Vt.getRowDimension(); j++) { sumNum += Vt.getEntry(j, v1) * Vt.getEntry(j, v2); fdenom += Math.pow(Vt.getEntry(j, v1), 2); sdenom += Math.pow(Vt.getEntry(j, v2), 2); }//from w w w. j a v a 2 s . c o m sim = sumNum / (Math.sqrt(fdenom) * Math.sqrt(sdenom)); return sim; }
From source file:edu.oregonstate.eecs.mcplan.ml.MatrixAlgorithms.java
public static RealMatrix makePositiveDefinite(final RealMatrix M, final double eps) { assert (eps > 0.0); final SingularValueDecomposition svd = new SingularValueDecomposition(M); final RealMatrix Sigma = svd.getS().copy(); final int N = Math.min(Sigma.getColumnDimension(), Sigma.getRowDimension()); for (int i = 0; i < N; ++i) { final double lambda = Sigma.getEntry(i, i); System.out.println("lambda_" + i + " = " + lambda); if (Math.abs(lambda) < eps) { System.out.println("Corrected " + i); Sigma.setEntry(i, i, eps);// ww w . j av a2s. c om } else if (lambda < 0.0) { throw new NonPositiveDefiniteMatrixException(lambda, i, eps); } else { Sigma.setEntry(i, i, lambda); } } return svd.getU().multiply(Sigma).multiply(svd.getVT()); }
From source file:edu.oregonstate.eecs.mcplan.ml.MatrixAlgorithms.java
/** * Computes the inverse of a matrix using the singular value decomposition. * // w ww. ja v a 2 s .c o m * The input matrix M is assumed to be positive definite up to numerical * precision 'eps'. That is, for all eigenvalues lambda of M, it must be * the case that lambda + eps > 0. For eigenvalues with |lambda| < eps, the * eigenvalue is set to 'eps' before inverting. Throws an exception if * any lambda < -eps. * @param M * @param eps * @return */ public static RealMatrix robustInversePSD(final RealMatrix M, final double eps) { assert (eps > 0.0); final SingularValueDecomposition svd = new SingularValueDecomposition(M); final RealMatrix Sigma = svd.getS().copy(); final int N = Math.min(Sigma.getColumnDimension(), Sigma.getRowDimension()); for (int i = 0; i < N; ++i) { final double lambda = Sigma.getEntry(i, i); System.out.println("lambda_" + i + " = " + lambda); if (Math.abs(lambda) < eps) { System.out.println("Corrected " + i); Sigma.setEntry(i, i, 1.0 / eps); } else if (lambda < 0.0) { throw new IllegalArgumentException("Negative eigenvalue " + lambda); } else { Sigma.setEntry(i, i, 1.0 / lambda); } } return svd.getV().multiply(Sigma.transpose()).multiply(svd.getUT()); }