|
@@ -9,11 +9,13 @@ namespace _06_Newton_uklady_rownan
|
|
|
public class Newton_Raphson
|
|
|
{
|
|
|
public int licznik;
|
|
|
+ private int n;
|
|
|
|
|
|
public double[] Oblicz(double eps, double[] x0, FW[] fn, FW[,] fprim)
|
|
|
{
|
|
|
+ n = x0.Length;
|
|
|
licznik = 0;
|
|
|
- double[] h = null;
|
|
|
+ double[] h;
|
|
|
double[] x = (double[])x0.Clone();
|
|
|
do
|
|
|
{
|
|
@@ -22,13 +24,12 @@ namespace _06_Newton_uklady_rownan
|
|
|
double[,] J = liczJ(fprim, x);
|
|
|
h = liczH(J, B);
|
|
|
Dodaj(x, h);
|
|
|
- } while (norma(h) > eps);
|
|
|
+ } while (Norma(h) > eps);
|
|
|
return x;
|
|
|
}
|
|
|
|
|
|
private void Dodaj(double[] x, double[] h)
|
|
|
{
|
|
|
- int n = x.Length;
|
|
|
for (int i = 0; i < n; i++)
|
|
|
x[i] = x[i] + h[i];
|
|
|
}
|
|
@@ -45,7 +46,6 @@ namespace _06_Newton_uklady_rownan
|
|
|
|
|
|
private double[,] liczJ(FW[,] fprim, double[] x)
|
|
|
{
|
|
|
- int n = x.Length;
|
|
|
double[,] J = new double[n, n];
|
|
|
for (int i = 0; i < n; i++)
|
|
|
for (int j = 0; j < n; j++)
|
|
@@ -55,20 +55,19 @@ namespace _06_Newton_uklady_rownan
|
|
|
|
|
|
private double[] liczB(FW[] fn, double[] x)
|
|
|
{
|
|
|
- int n = x.Length;
|
|
|
double[] B = new double[n];
|
|
|
for (int i = 0; i < n; i++)
|
|
|
B[i] = -fn[i](x);
|
|
|
return B;
|
|
|
}
|
|
|
|
|
|
- private double norma(double[] h)
|
|
|
+ private double Norma(double[] h)
|
|
|
{
|
|
|
- double nor = 0;
|
|
|
- foreach (double v in h)
|
|
|
- nor = nor + v * v;
|
|
|
- nor = Math.Sqrt(nor);
|
|
|
- return nor;
|
|
|
+ double norma = 0;
|
|
|
+ for (int i = 0; i < n; i++)
|
|
|
+ norma = norma + h[i] * h[i];
|
|
|
+ norma = Math.Sqrt(norma);
|
|
|
+ return norma;
|
|
|
}
|
|
|
}
|
|
|
}
|