Javaの数値計算ライブラリApache Commons Mathを使う(2) 補間を行う(Interpolate) リニア、Akimaスプラインなどいろいろある。JFreeChartで散布図とXYプロットを描く。
今回は補間。
いろいろあるがリニアとAkima(秋間)スプラインを使ってみよう。
コードはこんな感じ。
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.AkimaSplineInterpolator;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
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;
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Interpolation extends JFrame {
public static void main(String[] args) {
Interpolation frame = new Interpolation();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(10, 10, 640, 480);
frame.setTitle("Interpolation");
frame.setVisible(true);
}
public Interpolation() {
JFreeChart chart =
ChartFactory.createXYLineChart("Interpolation",
"x",
"y",
createData(),
PlotOrientation.VERTICAL,
true,
false,
false);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer =new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(0, false);
renderer.setSeriesShapesVisible(1, false);
renderer.setSeriesShapesVisible(2, false);
plot.setRenderer(renderer);
ChartPanel cpanel = new ChartPanel(chart);
getContentPane().add(cpanel, BorderLayout.CENTER);
}
private XYSeriesCollection createData(){
int n = 10;
double[] x = new double[n];
double[] y = new double[n];
for (int i = 0; i < n; i++) {
x[i] = 2.0 * Math.PI * (double)i / (double)(n - 1);
y[i] = Math.sin(x[i]);
}
int m = 50;
double[] xval = new double[m];
double[] yline = new double[m];
double[] yakima = new double[m];
LinearInterpolator linearInterpolator = new LinearInterpolator();
AkimaSplineInterpolator akimaSplineInterpolator = new AkimaSplineInterpolator();
UnivariateFunction lineFunction = linearInterpolator.interpolate(x, y);
UnivariateFunction akimaFunction = akimaSplineInterpolator.interpolate(x, y);
for (int i = 0; i < m; i++) {
xval[i] = 2.0 * Math.PI * (double)i / (double)(m - 1);
yline[i] = lineFunction.value(xval[i]);
yakima[i] = akimaFunction.value(xval[i]);
}
XYSeriesCollection data = new XYSeriesCollection();
XYSeries series1 = new XYSeries("Original Points");
for (int i = 0 ; i < n ; i++){
series1.add(x[i], y[i]);
}
XYSeries series2 = new XYSeries("Linear");
for (int i = 0 ; i < m ; i++){
series2.add(xval[i], yline[i]);
}
XYSeries series3 = new XYSeries("Spline");
for (int i = 0 ; i < m ; i++){
series3.add(xval[i], yakima[i]);
}
data.addSeries(series1);
data.addSeries(series2);
data.addSeries(series3);
return data;
}
}
|
実行結果。
ちゃんと補間されている。
« ルクア大阪 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 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)



コメント