Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. namespace Math_lab1
  3. {
  4.     public class SimpleIteration : RefinmentMethod
  5.     {
  6.         readonly MathFunction compressionFunction;
  7.         readonly double q;
  8.         public SimpleIteration(
  9.             DifferentiableFunction function,
  10.             double leftBorder,
  11.             double rightBorder,
  12.             double accuracy
  13.         ) : base(function, leftBorder, rightBorder, accuracy)
  14.         {
  15.  
  16.             double alpha = Math.Min(
  17.                 function.GetFirstDerivativeValue(leftBorder),
  18.                 function.GetFirstDerivativeValue(rightBorder)
  19.                 );
  20.             double gamma = Math.Max(
  21.                 function.GetFirstDerivativeValue(leftBorder),
  22.                 function.GetFirstDerivativeValue(rightBorder)
  23.                 );
  24.             double lambda = 2 / (alpha + gamma);
  25.             Console.WriteLine(lambda);
  26.             q = (gamma - alpha) / (gamma + alpha);
  27.             compressionFunction = function.GetCompressionFunction(lambda);
  28.         }
  29.  
  30.         public override double Solve()
  31.         {
  32.             int k = 0;
  33.             double x, currAccuracy;
  34.             double xPrevious = rightBorder;
  35.  
  36.             do
  37.             {
  38.                 x = compressionFunction.GetValue(xPrevious);
  39.                 k += 1;
  40.                 Console.WriteLine("{0} {1}", k, x);
  41.                 currAccuracy = Math.Abs(xPrevious - x);
  42.                 xPrevious = x;
  43.             } while (currAccuracy > Math.Abs((1 - q) * accuracy / q));
  44.             return x;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement