Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace МПИ_СЛАУ
- {
- class Program
- {
- delegate double func(double[] x);
- static void Main(string[] args)
- {
- const double eps = 0.00001;
- func x1 = (x) => 0 *x[0] - 2.42 / 40.41 * x[1] -3.86/40.41 * x[2] + 20.41/40.41;
- func x2 = (x) => -2.31/21.49 * x[0] + 0 * x[1] - 4.55/21.49 * x[2] + 30.11/21.49;
- func x3 = (x) => -2.49 / 25.69 * x[0] - 4.85 / 25.96 * x[1] + 0 * x[2] + 12.24/25.96;
- double norma = 0.31;
- var xn = new double[3] { 0.51, 1.4,0.47};
- var f = new double[3] { x1(xn), x2(xn), x3(xn) };
- while (norma /(1-norma) * f.Diff(xn).Abs().Max() > eps)
- {
- xn = new double[3] { x1(xn), x2(xn), x3(xn) };
- f = new double[3] { x1(xn), x2(xn), x3(xn) };
- }
- Console.WriteLine("{0} {1} {2}", f[0], f[1], f[2]);
- }
- }
- public static class MyExtension
- {
- public static double[] Diff(this double[] a, double[] b)
- {
- if (a.Length == 3 && b.Length == 3)
- return new double[] { a[0] - b[0], a[1] - b[1], a[2] - b[2] };
- else throw new ArgumentOutOfRangeException();
- }
- 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