私はここにいるのは初めてで、おそらくそこの専門家が私を助けてくれることを願っていますf(x) = a *sin(b* (x+c))+d
.C#のライブラリ「math.net numerics」を介して正弦関数を当てはめたいです。
最初に、次のサンプル コードを試しました。
// data points: we compute y perfectly but then add strong random noise to it
var rnd = new Random(1);
var omega = 1.0d
var xdata = new double[] { -1, 0, 0.1, 0.2, 0.3, 0.4, 0.65, 1.0, 1.2, 2.1, 4.5, 5.0, 6.0 };
var ydata = xdata.Select(x => 5 + 2 * Math.Sin(omega*x + 0.2) + 2*(rnd.NextDouble()-0.5)).ToArray();
// build matrices
var X = DenseMatrix.OfColumns(new[] {
new DenseVector(1),
new DenseVector(xdata.Select(t => Math.Sin(omega*t)).ToArray()),
new DenseVector(xdata.Select(t => Math.Cos(omega*t)).ToArray())});
var y = new DenseVector(ydata);
// solve
var p = X.QR().Solve(y);
var a = p[0];
var b = SpecialFunctions.Hypotenuse(p[1], p[2]);
var c = Math.Atan2(p[2], p[1]);
しかし、その結果、プログラムは次のエラーを返しました。
「マトリックスの寸法は一致する必要があります: 1x3」.
問題を解決するために何ができるかヒントをいただけますか?