Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace нелинейная_система
- {
- class Program
- {
- static void Main(string[] args)
- {
- const double eps = 0.0001;
- Console.WriteLine("Пара корней системы ");
- var xn = MPI(new double[2] { 0.6, 0.5 }, eps);
- Console.WriteLine("x=[{0} {1}]", xn[0],xn[1]);
- }
- public static double[] MPI(double[] xn, double eps)
- {
- int counter = 0;
- while (Norma(F(xn), xn) > eps && Norma(xn) > eps)
- {
- xn = F(xn);
- Console.WriteLine("Итерация № {0} x1 = {1} x2 = {2}", counter++, xn[0], xn[1]);
- }
- xn = new double[] { Math.Round(xn[0], 4), Math.Round(xn[1], 4) };
- return xn;
- }
- public static double[] F(double [] x) => new double[] { Math.Sqrt(1 - Math.Pow(x[1], 2)), 2 * x[0] * Math.Exp(-x[0]) };
- public static double Norma(double[] a, double[] b) => a.Diff(b).Abs().Max();
- public static double Norma(double[] a) => a.Abs().Max();
- }
- public static class MyExtension
- {
- public static double[] Diff(this double[] a, double[] b)
- {
- if (a.Length != b.Length) throw new ArgumentException();
- var ar = new double[a.Length];
- for (int i = 0; i < a.Length; ++i) ar[i] = a[i] - b[i];
- return ar;
- }
- public static double Max(this double [] a)
- {
- double max = a[0];
- foreach (var n in a) if (n > max) max = n;
- return max;
- }
- public static double[] Abs(this double[] a)
- {
- for (int i = 0; i < a.Length; ++i) a[i] *= a[i] > 0 ? 1 : -1;
- return a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement