public RationalFraction Minus(RationalFraction b) { RationalFraction reducedFractionA, reducedFractionB; //дроби приведенные к знаменателю ReductionDenominator(this, b, out reducedFractionA, out reducedFractionB); return(new RationalFraction(reducedFractionA.numerator - reducedFractionB.numerator, reducedFractionA.denominator)); }
//приведение к общему знаменателю public static void ReductionDenominator(RationalFraction rfA, RationalFraction rfB, out RationalFraction rfC, out RationalFraction rfD) { if (!(rfA.denominator == rfB.denominator)) { rfC = new RationalFraction(rfA.numerator * rfB.denominator, rfA.denominator * rfB.denominator); rfD = new RationalFraction(rfB.numerator * rfA.denominator, rfA.denominator * rfB.denominator); } else { rfC = new RationalFraction(rfA.numerator, rfA.denominator); rfD = new RationalFraction(rfB.numerator, rfB.denominator); } }
private static RrFunction BinaryOp(SplineInterpoler left, SplineInterpoler right, FracBinaryOp binaryOp) { double[] mergedPillars = ArrayUtils.MergeSortedArray(left.pillars, right.pillars); var binOpElems = mergedPillars.Select(p => { RationalFraction leftElem = BasedSpline(left.stepSplines, p); RationalFraction rightElem = BasedSpline(right.stepSplines, p); return(binaryOp(leftElem, rightElem)); }).ToArray(); RationalFraction leftExtrapol = BasedExtrapol(left.stepSplines, mergedPillars.First()); RationalFraction rightExtrapol = BasedExtrapol(right.stepSplines, mergedPillars.First()); RationalFraction binOpExtrapol = binaryOp(leftExtrapol, rightExtrapol); var stepSplines = new StepFunction <RationalFraction>(mergedPillars, binOpElems, binOpExtrapol); return(new SplineInterpoler(stepSplines)); }
static void Task3() { string Welcome = "Вы выбрали задачу работы с комплексными числами\n"; Welcome = Welcome + "Это так весело!\n"; Welcome = Welcome + "Давайте начнем.\n"; Welcome = Welcome + "1 - Сложение дробей\n"; Welcome = Welcome + "2 - Вычитание дробей\n"; Welcome = Welcome + "3 - Умножение дробей\n"; Welcome = Welcome + "4 - Деление дробей\n"; Welcome = Welcome + "0 - Выход в предыдущее меню\n"; ClassLibraryLesson3.PrintTaskWelcomeScreen(Welcome); bool menuExit = false; #region инициализация переменных RationalFraction frA = new RationalFraction(6, 3); RationalFraction frB = new RationalFraction(3, 4); #endregion инициализация переменных while (!(menuExit)) { ClassLibraryLesson3.PrintTaskWelcomeScreen(Welcome); ConsoleKeyInfo userChooseKey = Console.ReadKey(true); switch (userChooseKey.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: ClassLibraryLesson3.Print($"Операция: дробь: <{frA.ToString()}> + дробь: <{frB.ToString()}> = <{frA.Plus(frB).ToString(true)}>"); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: ClassLibraryLesson3.Print($"Операция: дробь: <{frA.ToString()}> - дробь: <{frB.ToString()}> = <{frA.Minus(frB).ToString(true)}>"); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: ClassLibraryLesson3.Print($"Операция: дробь: <{frA.ToString()}> * дробь: <{frB.ToString()}> = <{frA.Multi(frB).ToString(true)}>"); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: ClassLibraryLesson3.Print($"Операция: дробь: <{frA.ToString()}> / дробь: <{frB.ToString()}> = <{frA.Dev(frB).ToString(true)}>"); break; case ConsoleKey.D0: case ConsoleKey.NumPad0: menuExit = true; // на выход break; } if (!(menuExit)) { ClassLibraryLesson3.Pause("Нажмите любую клавишу."); } } }
public RationalFraction Dev(RationalFraction b) { return(new RationalFraction(this.numerator * b.denominator, this.denominator * b.numerator)); }
//упрощение дроби через НОД public static RationalFraction Simplification(RationalFraction fr) { int nod = GetNOD(fr.numerator, fr.denominator); return(new RationalFraction(fr.numerator / nod, fr.denominator / nod)); }
public static Complex Evaluate(RationalFraction f, Complex x) { return(Evaluate(f.Top, x) / Evaluate(f.Bottom, x)); }