Пытаюсь разобраться в численном дифференцировании. И передо мной стоит задачу решить "краевую задачу".
Собственно проблема насколько мне известно,где-то в решении, мы должны решить СЛАУ одним из методов. У меня есть готовый Гаусс. По каким значения нужно строить матрицу? Вот наработки:
class Program
{
public static void Main()
{
double[] T = new double[] { 0, 1, 2, 3 };
List<double> y = new List<double>();
List<double> y_e = new List<double>();
List<double> e = new List<double>();
//y[0] = 0;
//y_e[0] = 0;
double j = 1;
for (double i = 0.01; i < 0.04; i += 0.01)
{
y.Add(DoubleDiff(j, ref i) + j * j * (Diff(F(j) * (j - T[Convert.ToInt32(j)]), ref i)) + j * j * j * (F(j) * (j - T[Convert.ToInt32(j)])));
y_e.Add(16 * Math.Pow(j, 3) * (j - i));
j++;
}
Console.WriteLine();
for (int i = 0; i < T.Length - 1; i++)
{
Console.Write(i + 1 + " ");
}
Console.WriteLine();
for (int i = 0; i < T.Length - 1; i++)
{
Console.Write(y[i] + " ");
}
Console.WriteLine();
for (int i = 0; i < T.Length - 1; i++)
{
Console.Write(y_e[i] + " ");
}
Console.WriteLine();
for (int i = 0; i < y.Count; i++)
{
e.Add(y_e[i] - y[i]);
Console.Write(e[i] + " ");
}
}
static double F(double x)
{
return 16 * Math.Pow(x, 3);
}
static double Diff(double x, ref double index)//производная первого порядка
{
return (F(Convert.ToInt32(x) + index) - F(Convert.ToInt32(x) - index)) / (2 * index);
}
static double DoubleDiff(double x, ref double index)//производная второго порядка
{
return (F(Convert.ToInt32(x) + index) - 2 * F(Convert.ToInt32(x)) + F(Convert.ToInt32(x) - index)) / Math.Pow(index, 2);
}
}