« 高周波・RFニュース 2025年10月23日 Samsung Galaxy XR発表、IEEE Antenna and Propagation MagazineでArtificial Impedance surfaceのレビュー、SEMCOが車載Molded Frame Capacitor 2220 inch C0G 1000V 54 nF発表、RCRWirelessのWi-Fi 8解説記事 | トップページ | 高周波・RFニュース 2025年10月24日 QorvoがSub1GHzのパワーアンプ発表、TDKがメタルパワーインダクタTFMシリーズ解説、Yoleがパッケージング用ガラス材料を調査、GSAがエンタープライズ5Gのウェビナー開催、TechInsightsがXiaomi 17 Pro Max を分解 »

2025年10月23日 (木)

Javaの数値計算ライブラリApache Commons Mathを使う(10) 数値積分を行う。いろいろなものが使えるがとりあえずSimpson公式とGauss-Legendre公式で。

今回はこちらの例題から。

 Visual C# (C_sharp)の数値計算ライブラリ MathNET Numericsを使う(10) 数値積分としてガウス・クロンロッド積分公式と二重指数関数型積分公式を試す。

使える公式が違うので今回はSimpson公式とGauss-Legendre公式で
∫4/(1+x^2)dx (積分範囲[0,1])

をやってみる。

コードはこんな感じ。


import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator;
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory;

public class integration {
    public static class Myfunction implements UnivariateFunction {
        public double value(double x) {
            return  4.0 / (1.0 + x * x);
        }
    }
   
    public static void main(String[] args) {
        UnivariateFunction function = new Myfunction();
        SimpsonIntegrator integrator = new SimpsonIntegrator();

        double lowerBound = 0.0;
        double upperBound = 1.0;
       
        double result = integrator.integrate(500, function, lowerBound, upperBound);
        System.out.println("Integration result: " + result + " Simpson公式");
 
        GaussIntegratorFactory factory = new GaussIntegratorFactory();
        GaussIntegrator integrator2 = factory.legendre(15, 0.0, 1.0);
        double result2 = integrator2.integrate(function);
        System.out.println("Integration result: " + result2 + " Gauss-Legendreの公式");

    }
}

結果はこちら。やっぱりGauss-Legendreの方が精度がよさそう。



Integration result: 3.1415926512248222 Simpson公式

Integration result: 3.1415926535897936 Gauss-Legendreの公式

 

 

 

« 高周波・RFニュース 2025年10月23日 Samsung Galaxy XR発表、IEEE Antenna and Propagation MagazineでArtificial Impedance surfaceのレビュー、SEMCOが車載Molded Frame Capacitor 2220 inch C0G 1000V 54 nF発表、RCRWirelessのWi-Fi 8解説記事 | トップページ | 高周波・RFニュース 2025年10月24日 QorvoがSub1GHzのパワーアンプ発表、TDKがメタルパワーインダクタTFMシリーズ解説、Yoleがパッケージング用ガラス材料を調査、GSAがエンタープライズ5Gのウェビナー開催、TechInsightsがXiaomi 17 Pro Max を分解 »

パソコン・インターネット」カテゴリの記事

学問・資格」カテゴリの記事

日記・コラム・つぶやき」カテゴリの記事

コメント

コメントを書く

(ウェブ上には掲載しません)

« 高周波・RFニュース 2025年10月23日 Samsung Galaxy XR発表、IEEE Antenna and Propagation MagazineでArtificial Impedance surfaceのレビュー、SEMCOが車載Molded Frame Capacitor 2220 inch C0G 1000V 54 nF発表、RCRWirelessのWi-Fi 8解説記事 | トップページ | 高周波・RFニュース 2025年10月24日 QorvoがSub1GHzのパワーアンプ発表、TDKがメタルパワーインダクタTFMシリーズ解説、Yoleがパッケージング用ガラス材料を調査、GSAがエンタープライズ5Gのウェビナー開催、TechInsightsがXiaomi 17 Pro Max を分解 »

最近の記事

2025年11月
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
無料ブログはココログ
フォト