Javaの数値計算ライブラリApache Commons Mathを使う(4) 多項式フィッティング(今回は3次)をしてJFreeChartでプロットする。
今回はこの例題から。
Visual C# (C_sharp)の数学ライブラリ Math.NET Numericsを使う(4) 多項式フィッティングをして、Array.ConvertAllで一括でフィッティングデータを得る。
コードはこんな感じ。
import java.awt.BorderLayout;
import javax.swing.JFrame;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.fitting.PolynomialCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoints;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class CubicFit extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
CubicFit frame = new CubicFit();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(10, 10, 640, 480);
frame.setTitle("Cubic Polynomial Fitting");
frame.setVisible(true);
}
public CubicFit() {
JFreeChart chart =
ChartFactory.createXYLineChart("Polynomial Fitting",
"x",
"y",
createData(),
PlotOrientation.VERTICAL,
true,
false,
false);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer =new XYLineAndShapeRenderer();
NumberAxis yNumAxis = (NumberAxis)plot.getRangeAxis();
yNumAxis.setRange(-2.0, 2.0);
renderer.setSeriesLinesVisible(0, false);
renderer.setSeriesShapesVisible(1, false);
plot.setRenderer(renderer);
ChartPanel cpanel = new ChartPanel(chart);
getContentPane().add(cpanel, BorderLayout.CENTER);
}
private XYSeriesCollection createData(){
double[] x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
double[] y = {0.0, 0.8, 0.9, 0.1, -0.8, -1.0};
WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < x.length; i++) {
obs.add(x[i], y[i]);
}
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(3);
double[] coeff = fitter.fit(obs.toList());
PolynomialFunction cubicFitFunction = new PolynomialFunction(coeff);
double[] xval = new double[600];
double[] yval = new double[600];
for (int i = 0; i < xval.length; i++) {
xval[i] = -2.0 + (6.0 - (-2.0)) * (double)i / (double) (xval.length - 1);
yval[i] = cubicFitFunction.value(xval[i]);
}
XYSeriesCollection data = new XYSeriesCollection();
XYSeries series1 = new XYSeries("Original Points");
for (int i = 0 ; i < x.length ; i++){
series1.add(x[i], y[i]);
}
XYSeries series2 = new XYSeries("Cubic Fitting");
for (int i = 0 ; i < xval.length ; i++){
series2.add(xval[i], yval[i]);
}
data.addSeries(series1);
data.addSeries(series2);
return data;
}
}
|
結果はこちら。
« 高周波・RFニュース 特別編 iFixitがiPhone Airを分解、MLB(Main Logic Board)めちゃくちゃ小さい。REWAやPBKreviewsがiPhone 17 Proを分解、これもMLB小さい。5Gミリ波AiPは一番上に一個、iPhone17はMLB形状も含めてiPhone16とほとんど同じ | トップページ | 高周波・RFニュース 2025年9月23日 Next G Allianceが6Gレポート発行、EuMW2025開幕・日本ガイシがSubTHz用複合ウェハなど発表、Qualcomm Snapdragon Summit 2025は23日から、MediaTekがDimensity 9500発表、Nordicの新SoC、RCRwirelessの6Gレポート、など »
「パソコン・インターネット」カテゴリの記事
- RF Weekly Digest (Gemini 3 Pro・Google AI Studio BuildによるAIで高周波・RF情報の週刊まとめアプリ) 2026/2/1-2026/2/8(2026.02.08)
- Google Antigravityで、いつも見ている高周波関連サイト数十をスクレイピングしてローカルLLM(OllamaのQwen3:8b)で1週間分まとめてもらうRF Weekly Digestを作ってもらった。モデルはGemini 3 Proで。Google AI StudioのBuildで作ったものよりはちょっと劣るか。(2026.02.10)
- RF Weekly Digest (Gemini 3 Pro・Google AI Studio BuildによるAIで高周波・RF情報の週刊まとめアプリ) 2026/1/25-2026/2/1(2026.02.01)
「学問・資格」カテゴリの記事
- 高周波・RFニュース 2026年2月13日 GSMAが農村部の通信改善には1GHz以下が必要とレポート、Skyworksがクロックバッファのラインアップ拡充、YageoがWi-Fi 7向けグランド非依存アンテナ発表、SamsungがHBM4量産など(2026.02.13)
- 高周波・RFニュース 2026年2月12日 IEEE Antenna and Propagation Magazineに量子アニーリングの記事、AI-Drivenワイヤレスサミットが3月末に開催、3GPPのCT, SA WG会議がインドのゴア州で開催中、Infineon GaN Insights 2026(2026.02.12)
- 高周波・RFニュース 2026年2月11日 IEEE Microwave Magazineは女性研究者特集、Emerson/NIの2026年通信業界トレンドのホワイトペーパー、アンリツが6G FR3対応の測定器発表、GSAの2月度NTNレポートなど(2026.02.11)
- RF Weekly Digest (Gemini 3 Pro・Google AI Studio BuildによるAIで高周波・RF情報の週刊まとめアプリ) 2026/2/1-2026/2/8(2026.02.08)
- Google Antigravityで、いつも見ている高周波関連サイト数十をスクレイピングしてローカルLLM(OllamaのQwen3:8b)で1週間分まとめてもらうRF Weekly Digestを作ってもらった。モデルはGemini 3 Proで。Google AI StudioのBuildで作ったものよりはちょっと劣るか。(2026.02.10)
「日記・コラム・つぶやき」カテゴリの記事
- 高周波・RFニュース 2026年2月13日 GSMAが農村部の通信改善には1GHz以下が必要とレポート、Skyworksがクロックバッファのラインアップ拡充、YageoがWi-Fi 7向けグランド非依存アンテナ発表、SamsungがHBM4量産など(2026.02.13)
- 高周波・RFニュース 2026年2月12日 IEEE Antenna and Propagation Magazineに量子アニーリングの記事、AI-Drivenワイヤレスサミットが3月末に開催、3GPPのCT, SA WG会議がインドのゴア州で開催中、Infineon GaN Insights 2026(2026.02.12)
- 高周波・RFニュース 2026年2月11日 IEEE Microwave Magazineは女性研究者特集、Emerson/NIの2026年通信業界トレンドのホワイトペーパー、アンリツが6G FR3対応の測定器発表、GSAの2月度NTNレポートなど(2026.02.11)
- RF Weekly Digest (Gemini 3 Pro・Google AI Studio BuildによるAIで高周波・RF情報の週刊まとめアプリ) 2026/2/1-2026/2/8(2026.02.08)
- Google Antigravityで、いつも見ている高周波関連サイト数十をスクレイピングしてローカルLLM(OllamaのQwen3:8b)で1週間分まとめてもらうRF Weekly Digestを作ってもらった。モデルはGemini 3 Proで。Google AI StudioのBuildで作ったものよりはちょっと劣るか。(2026.02.10)
« 高周波・RFニュース 特別編 iFixitがiPhone Airを分解、MLB(Main Logic Board)めちゃくちゃ小さい。REWAやPBKreviewsがiPhone 17 Proを分解、これもMLB小さい。5Gミリ波AiPは一番上に一個、iPhone17はMLB形状も含めてiPhone16とほとんど同じ | トップページ | 高周波・RFニュース 2025年9月23日 Next G Allianceが6Gレポート発行、EuMW2025開幕・日本ガイシがSubTHz用複合ウェハなど発表、Qualcomm Snapdragon Summit 2025は23日から、MediaTekがDimensity 9500発表、Nordicの新SoC、RCRwirelessの6Gレポート、など »



コメント