/** Get the converted matrix. * @return converted matrix */ Array2DRowRealMatrix getConvertedMatrix() { return new Array2DRowRealMatrix(data, false); }
/** {@inheritDoc} */ @Override public RealMatrix add(final RealMatrix m) throws IllegalArgumentException { try { return add((Array2DRowRealMatrix) m); } catch (ClassCastException cce) { return super.add(m); } }
/** * Create a new RealMatrix using the input array as the underlying * data array. * <p>The input array is copied, not referenced. This constructor has * the same effect as calling {@link #Array2DRowRealMatrix(double[][], boolean)} * with the second argument set to <code>true</code>.</p> * * @param d data for new matrix * @throws IllegalArgumentException if <code>d</code> is not rectangular * (not all rows have the same length) or empty * @throws NullPointerException if <code>d</code> is null * @see #Array2DRowRealMatrix(double[][], boolean) */ public Array2DRowRealMatrix(final double[][] d) throws IllegalArgumentException, NullPointerException { copyIn(d); }
/** {@inheritDoc} */ @Override public RealMatrix copy() { return new Array2DRowRealMatrix(copyOut(), false); }
/** Initialize the high order scaled derivatives at step start. * @param first first scaled derivative at step start * @param multistep scaled derivatives after step start (hy'1, ..., hy'k-1) * will be modified * @return high order derivatives at step start */ public Array2DRowRealMatrix initializeHighOrderDerivatives(final double[] first, final double[][] multistep) { for (int i = 0; i < multistep.length; ++i) { final double[] msI = multistep[i]; for (int j = 0; j < first.length; ++j) { msI[j] -= first[j]; } } return initialization.multiply(new Array2DRowRealMatrix(multistep, false)); }
/** * Returns a fresh copy of the underlying data array. * * @return a copy of the underlying data array. */ private double[][] copyOut() { final int nRows = this.getRowDimension(); final double[][] out = new double[nRows][this.getColumnDimension()]; // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; }
/** * Compute this minus <code>m</code>. * * @param m matrix to be subtracted * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final double[][] outData = new double[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final double[] dataRow = data[row]; final double[] mRow = m.data[row]; final double[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col] - mRow[col]; } } return new Array2DRowRealMatrix(outData, false); }
numArtificialVariables + getNumObjectiveFunctions() + 1; // + 1 is for RHS int height = constraints.size() + getNumObjectiveFunctions(); Array2DRowRealMatrix matrix = new Array2DRowRealMatrix(height, width); matrix.setEntry(0, 0, -1); matrix.setEntry(zIndex, zIndex, maximize ? 1 : -1); RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.getData(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1, maximize ? f.getConstantTerm() : -1 * f.getConstantTerm()); matrix.setEntry(zIndex, getSlackVariableOffset() - 1, getInvertedCoeffiecientSum(objectiveCoefficients)); copyArray(constraint.getCoefficients().getData(), matrix.getDataRef()[row]); matrix.setEntry(row, getSlackVariableOffset() - 1, getInvertedCoeffiecientSum(constraint.getCoefficients())); matrix.setEntry(row, width - 1, constraint.getValue()); matrix.setEntry(row, getSlackVariableOffset() + slackVar++, 1); // slack } else if (constraint.getRelationship() == Relationship.GEQ) { matrix.setEntry(row, getSlackVariableOffset() + slackVar++, -1); // excess matrix.setEntry(0, getArtificialVariableOffset() + artificialVar, 1); matrix.setEntry(row, getArtificialVariableOffset() + artificialVar++, 1);
/** Copy constructor. * @param interpolator interpolator to copy from. The copy is a deep * copy: its arrays are separated from the original arrays of the * instance */ public NordsieckStepInterpolator(final NordsieckStepInterpolator interpolator) { super(interpolator); scalingH = interpolator.scalingH; referenceTime = interpolator.referenceTime; if (interpolator.scaled != null) { scaled = interpolator.scaled.clone(); } if (interpolator.nordsieck != null) { nordsieck = new Array2DRowRealMatrix(interpolator.nordsieck.getDataRef(), true); } if (interpolator.stateVariation != null) { stateVariation = interpolator.stateVariation.clone(); } }
interpolator.reinitialize(stepStart, stepSize, scaled, nordsieck); interpolator.storeTime(stepStart); final int lastRow = nordsieck.getRowDimension() - 1; (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); final double ratio = nordsieck.getEntry(lastRow, i) / tol; error += ratio * ratio;
/** Rescale the instance. * <p>Since the scaled and Nordiseck arrays are shared with the caller, * this method has the side effect of rescaling this arrays in the caller too.</p> * @param stepSize new step size to use in the scaled and nordsieck arrays */ public void rescale(final double stepSize) { final double ratio = stepSize / scalingH; for (int i = 0; i < scaled.length; ++i) { scaled[i] *= ratio; } final double[][] nData = nordsieck.getDataRef(); double power = ratio; for (int i = 0; i < nData.length; ++i) { power *= ratio; final double[] nDataI = nData[i]; for (int j = 0; j < nDataI.length; ++j) { nDataI[j] *= power; } } scalingH = stepSize; }
/** {@inheritDoc} */ @Override public double[][] getData() { return copyOut(); }
/** * Returns the result of postmultiplying this by <code>m</code>. * @param m matrix to postmultiply by * @return this*m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkMultiplicationCompatible(this, m); final int nRows = this.getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final double[][] outData = new double[nRows][nCols]; for (int row = 0; row < nRows; row++) { final double[] dataRow = data[row]; final double[] outDataRow = outData[row]; for (int col = 0; col < nCols; col++) { double sum = 0; for (int i = 0; i < nSum; i++) { sum += dataRow[i] * m.data[i][col]; } outDataRow[col] = sum; } } return new Array2DRowRealMatrix(outData, false); }
numArtificialVariables + getNumObjectiveFunctions() + 1; // + 1 is for RHS int height = constraints.size() + getNumObjectiveFunctions(); Array2DRowRealMatrix matrix = new Array2DRowRealMatrix(height, width); matrix.setEntry(0, 0, -1); matrix.setEntry(zIndex, zIndex, maximize ? 1 : -1); RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.getData(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1, maximize ? f.getConstantTerm() : -1 * f.getConstantTerm()); matrix.setEntry(zIndex, getSlackVariableOffset() - 1, getInvertedCoeffiecientSum(objectiveCoefficients)); copyArray(constraint.getCoefficients().getData(), matrix.getDataRef()[row]); matrix.setEntry(row, getSlackVariableOffset() - 1, getInvertedCoeffiecientSum(constraint.getCoefficients())); matrix.setEntry(row, width - 1, constraint.getValue()); matrix.setEntry(row, getSlackVariableOffset() + slackVar++, 1); // slack } else if (constraint.getRelationship() == Relationship.GEQ) { matrix.setEntry(row, getSlackVariableOffset() + slackVar++, -1); // excess matrix.setEntry(0, getArtificialVariableOffset() + artificialVar, 1); matrix.setEntry(row, getArtificialVariableOffset() + artificialVar++, 1);
/** Copy constructor. * @param interpolator interpolator to copy from. The copy is a deep * copy: its arrays are separated from the original arrays of the * instance */ public NordsieckStepInterpolator(final NordsieckStepInterpolator interpolator) { super(interpolator); scalingH = interpolator.scalingH; referenceTime = interpolator.referenceTime; if (interpolator.scaled != null) { scaled = interpolator.scaled.clone(); } if (interpolator.nordsieck != null) { nordsieck = new Array2DRowRealMatrix(interpolator.nordsieck.getDataRef(), true); } if (interpolator.stateVariation != null) { stateVariation = interpolator.stateVariation.clone(); } }
/** * Returns a fresh copy of the underlying data array. * * @return a copy of the underlying data array. */ private double[][] copyOut() { final int nRows = this.getRowDimension(); final double[][] out = new double[nRows][this.getColumnDimension()]; // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; }
/** {@inheritDoc} */ @Override public RealMatrix copy() { return new Array2DRowRealMatrix(copyOut(), false); }
/** Initialize the high order scaled derivatives at step start. * @param first first scaled derivative at step start * @param multistep scaled derivatives after step start (hy'1, ..., hy'k-1) * will be modified * @return high order derivatives at step start */ public Array2DRowRealMatrix initializeHighOrderDerivatives(final double[] first, final double[][] multistep) { for (int i = 0; i < multistep.length; ++i) { final double[] msI = multistep[i]; for (int j = 0; j < first.length; ++j) { msI[j] -= first[j]; } } return initialization.multiply(new Array2DRowRealMatrix(multistep, false)); }
interpolator.reinitialize(stepStart, stepSize, scaled, nordsieck); interpolator.storeTime(stepStart); final int lastRow = nordsieck.getRowDimension() - 1; (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); final double ratio = nordsieck.getEntry(lastRow, i) / tol; error += ratio * ratio;
/** Update the high order scaled derivatives Adams integrators (phase 2). * <p>The complete update of high order derivatives has a form similar to: * <pre> * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> * </pre> * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p> * <p>Phase 1 of the update must already have been performed.</p> * @param start first order scaled derivatives at step start * @param end first order scaled derivatives at step end * @param highOrder high order scaled derivatives, will be modified * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix) */ public void updateHighOrderDerivativesPhase2(final double[] start, final double[] end, final Array2DRowRealMatrix highOrder) { final double[][] data = highOrder.getDataRef(); for (int i = 0; i < data.length; ++i) { final double[] dataI = data[i]; final double c1I = c1[i]; for (int j = 0; j < dataI.length; ++j) { dataI[j] += c1I * (start[j] - end[j]); } } }