Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Hipparchus project under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The Hipparchus project 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
*
* https://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.hipparchus.analysis.integration.gauss;

import org.hipparchus.util.FastMath;
import org.hipparchus.util.Pair;

/**
* Factory that creates Gauss-Chebyshev quadrature rules of the second kind.
*
* <p>The generated rules approximate integrals of the form:</p>
*
* <pre>
* integral from -1 to 1 of f(x) sqrt(1 - x^2) dx
* </pre>
*
* <p>using:</p>
*
* <pre>
* sum from i = 1 to n of w_i f(x_i)
* </pre>
*
* <p>where:</p>
*
* <pre>
* x_i = cos(i pi / (n + 1)), i = 1, ..., n
* w_i = pi / (n + 1) sin^2(i pi / (n + 1))
* </pre>
*/
public class ChebyshevSecondKindRuleFactory extends AbstractRuleFactory {

/**
* Computes the Gauss-Chebyshev quadrature rule of the second kind.
*
* @param numberOfPoints order of the rule to be computed
* @return nodes and weights of the quadrature rule
*/
@Override
protected Pair<double[], double[]> computeRule(final int numberOfPoints) {
final double[] points = new double[numberOfPoints];
final double[] weights = new double[numberOfPoints];

final double scale = FastMath.PI / (numberOfPoints + 1.0);

for (int i = 0; i < numberOfPoints; i++) {
final double angle = (i + 1.0) * scale;
final double sin = FastMath.sin(angle);
final int index = numberOfPoints - 1 - i;

points[index] = FastMath.cos(angle);
weights[index] = scale * sin * sin;
}

return new Pair<>(points, weights);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Hipparchus project under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The Hipparchus project 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
*
* https://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.hipparchus.analysis.integration.gauss;

import org.hipparchus.CalculusFieldElement;
import org.hipparchus.Field;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.MathArrays;
import org.hipparchus.util.Pair;

/**
* Factory that creates field-based Gauss-Chebyshev quadrature rules of the
* second kind.
*
* <p>The generated rules approximate integrals of the form:</p>
*
* <pre>
* integral from -1 to 1 of f(x) sqrt(1 - x^2) dx
* </pre>
*
* <p>using:</p>
*
* <pre>
* sum from i = 1 to n of w_i f(x_i)
* </pre>
*
* <p>where:</p>
*
* <pre>
* x_i = cos(i pi / (n + 1)), i = 1, ..., n
* w_i = pi / (n + 1) sin^2(i pi / (n + 1))
* </pre>
*
* @param <T> type of the field elements
*/
public class FieldChebyshevSecondKindRuleFactory<T extends CalculusFieldElement<T>>
extends FieldAbstractRuleFactory<T> {

/**
* Constructor.
*
* @param field field to which rule coefficients belong
*/
public FieldChebyshevSecondKindRuleFactory(final Field<T> field) {
super(field);
}

/**
* Computes the Gauss-Chebyshev quadrature rule of the second kind.
*
* @param numberOfPoints order of the rule to be computed
* @return nodes and weights of the quadrature rule
*/
@Override
protected Pair<T[], T[]> computeRule(final int numberOfPoints) {
final T[] points = MathArrays.buildArray(getField(), numberOfPoints);
final T[] weights = MathArrays.buildArray(getField(), numberOfPoints);

final T scale = getField().getZero().newInstance(FastMath.PI / (numberOfPoints + 1.0));

for (int i = 0; i < numberOfPoints; i++) {
final T angle = scale.multiply(i + 1.0);
final T sin = FastMath.sin(angle);
final int index = numberOfPoints - 1 - i;

points[index] = FastMath.cos(angle);
weights[index] = scale.multiply(sin.square());
}

return new Pair<>(points, weights);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class FieldGaussIntegratorFactory<T extends CalculusFieldElement<T>> {
private final FieldRuleFactory<T> hermite;
/** Generator of Gauss-Laguerre integrators. */
private final FieldRuleFactory<T> laguerre;
/** Generator of Gauss-Chebyshev integrators. */
private final FieldRuleFactory<T> chebyshevSecondKind;

/** Simple constructor.
* @param field field to which function argument and value belong
Expand All @@ -48,6 +50,7 @@ public FieldGaussIntegratorFactory(final Field<T> field) {
legendre = new FieldLegendreRuleFactory<>(field);
hermite = new FieldHermiteRuleFactory<>(field);
laguerre = new FieldLaguerreRuleFactory<>(field);
chebyshevSecondKind = new FieldChebyshevSecondKindRuleFactory<>(field);
}

/**
Expand Down Expand Up @@ -120,6 +123,20 @@ public SymmetricFieldGaussIntegrator<T> hermite(int numberOfPoints) {
return new SymmetricFieldGaussIntegrator<>(hermite.getRule(numberOfPoints));
}

/**
* Creates a Gauss-Chebyshev integrator of the second kind of the given order.
* The call to the
* {@link FieldGaussIntegrator#integrate(org.hipparchus.analysis.CalculusFieldUnivariateFunction)
* integrate} method will perform an integration on the natural interval
* {@code [-1 , 1]}.
*
* @param numberOfPoints Order of the integration rule.
* @return a Gauss-Chebyshev integrator.
*/
public FieldGaussIntegrator<T> chebyshevSecondKind(int numberOfPoints) {
return new FieldGaussIntegrator<>(chebyshevSecondKind.getRule(numberOfPoints));
}

/**
* Performs a change of variable so that the integration can be performed
* on an arbitrary interval {@code [a, b]}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class GaussIntegratorFactory {
private final RuleFactory hermite;
/** Generator of Gauss-Laguerre integrators. */
private final RuleFactory laguerre;
/** Generator of Gauss-Chebyshev integrators. */
private final RuleFactory chebyshevSecondKind;

/** Simple constructor.
*/
Expand All @@ -57,6 +59,7 @@ public GaussIntegratorFactory(final int decimalDigits) {
legendreHighPrecision = new ConvertingRuleFactory<>(new FieldLegendreRuleFactory<>(new DfpField(decimalDigits)));
hermite = new HermiteRuleFactory();
laguerre = new LaguerreRuleFactory();
chebyshevSecondKind = new ChebyshevSecondKindRuleFactory();
}

/**
Expand Down Expand Up @@ -146,6 +149,21 @@ public GaussIntegrator legendreHighPrecision(int numberOfPoints,
lowerBound, upperBound));
}

/**
* Creates a Gauss-Chebyshev integrator of the second kind of the given order.
* The call to the
* {@link GaussIntegrator#integrate(org.hipparchus.analysis.UnivariateFunction)
* integrate} method will perform an integration on the natural interval
* {@code [-1 , 1]}.
*
* @param numberOfPoints Order of the integration rule.
* @return a GaussChebyshev integrator.
*/
public GaussIntegrator chebyshevSecondKind(int numberOfPoints)
throws MathIllegalArgumentException {
return new GaussIntegrator(chebyshevSecondKind.getRule(numberOfPoints));
}

/**
* Creates a Gauss-Hermite integrator of the given order.
* The call to the
Expand Down
Loading