Hi guys!
I'm devloping in C# (an interpolation and approximation program) and I have wanted to implement a cubic spline method
http://www.vbforums.com/showthread.php?t=480806 (B section)
,but it hasn't worked, and I don't know where
is the mistake in my program or in the calculation.
The other things like solve of the tridigonal matrix,polynom etc. they work correctly.
Thanks for your help!
double[] h = new double[this.list.Count - 1];
for (int i = 0; i < h.Length; ++i)
{
}
double[] b = new double[list.Count];
b[0] = 0;
b[b.Length -1] = 0;
for (int i = 1; i < b.Length-1;++i)
{
}
double[] a1 = new double[list.Count];//a diagonális mátrix átlói
double[] a2 = new double[list.Count - 1];
double[] a3 = new double[list.Count - 1];
a1[0] = 1;
a1[a1.Length - 1] = 1;
for (int i = 1; i < a1.Length-1;++i)
{a1 = 2 * (h[i-1] + h;}
for (int i = 1; i < a2.Length;i++)
{a2 = h;}
for (int i = 0; i < a3.Length-1;++i
{a3 = h;}
TridiagonalMatrix splineSystem = new TridiagonalMatrix(a1, a2, a3);
double[] x = splineSystem.solve(b);
polynom = new Polynom[list.Count - 1];
double ai;
double bi;
double ci;
double di;
for (int i = 0; i < polynom.Length; ++i)
{
}
I'm devloping in C# (an interpolation and approximation program) and I have wanted to implement a cubic spline method
http://www.vbforums.com/showthread.php?t=480806 (B section)
,but it hasn't worked, and I don't know where
is the mistake in my program or in the calculation.
The other things like solve of the tridigonal matrix,polynom etc. they work correctly.
Thanks for your help!
double[] h = new double[this.list.Count - 1];
for (int i = 0; i < h.Length; ++i)
{
h = list[i + 1].x - list.x;
}
double[] b = new double[list.Count];
b[0] = 0;
b[b.Length -1] = 0;
for (int i = 1; i < b.Length-1;++i)
{
b = (list[i+1].y - list.y) / h - (list.y - list[i-1].y) / h[i-1];
b *= 6;
}
double[] a1 = new double[list.Count];//a diagonális mátrix átlói
double[] a2 = new double[list.Count - 1];
double[] a3 = new double[list.Count - 1];
a1[0] = 1;
a1[a1.Length - 1] = 1;
for (int i = 1; i < a1.Length-1;++i)
{a1 = 2 * (h[i-1] + h;}
for (int i = 1; i < a2.Length;i++)
{a2 = h;}
for (int i = 0; i < a3.Length-1;++i
{a3 = h;}
TridiagonalMatrix splineSystem = new TridiagonalMatrix(a1, a2, a3);
double[] x = splineSystem.solve(b);
polynom = new Polynom[list.Count - 1];
double ai;
double bi;
double ci;
double di;
for (int i = 0; i < polynom.Length; ++i)
{
polynom = new Polynom();
ai = (x[i + 1] - x) / 6 * h;
bi = x / 2;
ci = (list[i + 1].y - list.y) / h - x[i + 1] * h / 6 - x * h / 3;
di = list.y;
//di
ai = (x[i + 1] - x) / 6 * h;
bi = x / 2;
ci = (list[i + 1].y - list.y) / h - x[i + 1] * h / 6 - x * h / 3;
di = list.y;
//di
polynom.add_item(di, 0);
//ci(x-xi)
polynom.add_item(ci, 1);//ci * x
polynom.add_item(-ci * list.x, 0);
//bi(x-xi)^2
polynom.add_item(bi * (list.x * list.x), 0);
polynom.add_item(-2 * bi * list.x, 1);
polynom.add_item(bi, 2);
//ai(x-xi)^3
polynom.add_item(ai, 3);
polynom.add_item(-ai * 3 * list.x, 2);
polynom.add_item(ai * 3 * (list.x * list.x), 1);
polynom.add_item(-ai * (list.x * list.x * list.x), 0);
//ci(x-xi)
polynom.add_item(ci, 1);//ci * x
polynom.add_item(-ci * list.x, 0);
//bi(x-xi)^2
polynom.add_item(bi * (list.x * list.x), 0);
polynom.add_item(-2 * bi * list.x, 1);
polynom.add_item(bi, 2);
//ai(x-xi)^3
polynom.add_item(ai, 3);
polynom.add_item(-ai * 3 * list.x, 2);
polynom.add_item(ai * 3 * (list.x * list.x), 1);
polynom.add_item(-ai * (list.x * list.x * list.x), 0);
}