MATH-581
Framework for iterative solvers. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1145779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
85cb7a8d48
commit
bf05f11de3
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.commons.math.linear;
|
||||||
|
|
||||||
|
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface defines a {@link RealLinearOperator} which can be inverted.
|
||||||
|
* Preconditioners typically fall into this category.
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public abstract class InvertibleRealLinearOperator extends RealLinearOperator {
|
||||||
|
/**
|
||||||
|
* Creates a new instance of this class with the specified dimension.
|
||||||
|
*
|
||||||
|
* @param dim Common dimension of the domain and codomain.
|
||||||
|
*/
|
||||||
|
public InvertibleRealLinearOperator(final int dim) {
|
||||||
|
super(dim, dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the matrix-vector product of the inverse of this instance
|
||||||
|
* with {@code b} and returns the result.
|
||||||
|
*
|
||||||
|
* @param b Right-hand side vector.
|
||||||
|
* @return the left-hand side vector.
|
||||||
|
*/
|
||||||
|
public double[] solve(final double[] b) {
|
||||||
|
if (b.length != getRowDimension()) {
|
||||||
|
throw new DimensionMismatchException(b.length,
|
||||||
|
getRowDimension());
|
||||||
|
}
|
||||||
|
final RealVector x = solve(new ArrayRealVector(b, false));
|
||||||
|
if (x instanceof ArrayRealVector) {
|
||||||
|
return ((ArrayRealVector) x).getDataRef();
|
||||||
|
} else {
|
||||||
|
return x.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the matrix-vector product of the inverse of this instance
|
||||||
|
* with {@code b} and returns the result.
|
||||||
|
*
|
||||||
|
* @param b Right-hand side vector.
|
||||||
|
* @return the left-hand side vector.
|
||||||
|
*/
|
||||||
|
public abstract RealVector solve(final RealVector b);
|
||||||
|
}
|
Loading…
Reference in New Issue