double Si(double x, double a, double b, Funct f) { if ((x < a) || (x > b)) { throw new OutOfIntervalException("X is out of range of [x1,x2]!"); } if (x == a) { return(Ai(a, b, 0, f)); } int i = 0; double xi; do { i++; xi = a + i * h; }while (x > xi); double ai = Ai(a, b, i, f); double bi = Bi(i, a, f); double ci = X[i]; double di = Di(i); double delta = x - xi; return(ai + bi * delta + (ci * delta * delta) / 2 + (di * delta * delta * delta) / 2); }
public double Rectangles(int a, int b, int n, Funct f) // решение интеграла { // вычисление массива xj double[] x = new double[n]; // массив с иксами x[0] = a; for (int j = 1; j < n; j++) { // равный промежуток + предыдущий элемент // необходимо чтобы точки шли на прямой от a до b x[j] = (b - a)/(double)n + x[j-1]; } x[n-1] = b; // вычисление массива yj double[] y = new double[n-1]; for (int j = 1; j < n; j++) { y[j-1] = f((x[j - 1] + x[j])/2); } // вычисление суммы yi double sum = 0; foreach (double yi in y) { sum += yi; } // ответ - интеграл равен return sum*((b - a)/(double) n); }
static void CompTrapeziumRule(double eps, double a, double b, Funct function1, int k, int t) { int n = N; double result = TrapeziumCalc(a, b, function1, n, k, t); IN = result; }
public static void Tabulation(Funct fun, double a, double b, int n) { for (int k = 0; k < n; k++) { double result = a + k * (b - a) / n; Console.WriteLine($"{result} {fun(result)}"); } }
double Bi(int i, double a, Funct f) { double fi0 = f(a + h * (i - 1)); double fi = f(a + h * i); double di = Di(i); return((h * X[i]) / 2 - (di * h * h) / 6 + (fi - fi0) / h); }
void NewtonLeibniz(double a, double b, Funct antder) { if (a > b) { Swap(ref a, ref b); } Variables.Add("Iexact", (antder(b) - antder(a))); }
static public double DefineIntegral(double eps, double a, double b, Funct function1, int k, int t) { FindN1(eps, a, b); CompTrapeziumRule(eps, a, b, function1, k, t); RefinedCalc(eps, a, b, function1, k, t); double defintegral = I2N; return(defintegral); }
void Simpson(double a, double b, Funct function) { int n = (int)Variables["n"]; double result = SimpsonCalc(a, b, function, n); Variables.Add("In", result); double Error = Math.Abs(Variables["Iexact"] - result); Variables.Add("Error", Error); }
static double TrapeziumCalc(double a, double b, Funct function1, int n, int k, int t) { double Summ = 0, h = (double)(b - a) / n; for (int i = 1; i < n; i++) { Summ += function1(a + i * h, k, t); } return(h * (function1(a, k, t) / 2 + function1(b, k, t) / 2 + Summ)); }
void PrintSpline(int n, double a, double b, Funct f) { double x = 0.2, y; StreamWriter sw = new StreamWriter("Spline.txt", false, Encoding.Default); for (int i = 0; i < n; i++) { x = a + i * h; y = Si(x, a, b, f); sw.WriteLine("{0,6} {1}", x, y); Console.WriteLine("{0};{1}", x, y); } sw.Close(); }
static void RefinedCalc(double eps, double a, double b, Funct function1, int k, int t) { int n = N << 2; double In = IN; double I2n = TrapeziumCalc(a, b, function1, n, k, t), del = Math.Abs(In - I2n); while (del > 3 * eps) { In = I2n; n = n << 2; I2n = TrapeziumCalc(a, b, function1, n, k, t); del = Math.Abs((In - I2n) / I2n); } N2 = n; I2N = I2n; }
double SimpsonCalc(double a, double b, Funct function, int n) { double PairSumm = 0, OddSumm = 0, h = (double)(b - a) / n; for (int i = 1; i < n; i++) { if (i % 2 == 0) { PairSumm += function(a + i * h); } else { OddSumm += function(a + i * h); } } return(h / 3 * (function(a) + function(b) + 4 * OddSumm + 2 * PairSumm)); }
private void Initialize(string binary) { // Parsing binary code is based on Opcode this.Opcode = (Opcode)Convert.ToUInt32(binary.Substring(0, 6), 2); if (this.Opcode == Opcode.RType) { this.Type = FormatType.Register; } else if (this.Opcode == Opcode.j || this.Opcode == Opcode.jal) { this.Type = FormatType.Jump; } else if (this.Opcode == Opcode.halt) { this.Type = FormatType.Halt; } else { this.Type = FormatType.Immediate; } switch (this.Type) { case FormatType.Register: this.Rs = (RegisterType)Convert.ToUInt32(binary.Substring(6, 5), 2); this.Rt = (RegisterType)Convert.ToUInt32(binary.Substring(11, 5), 2); this.Rd = (RegisterType)Convert.ToUInt32(binary.Substring(16, 5), 2); this.Shamt = Convert.ToUInt32(binary.Substring(21, 5), 2); this.Funct = (Funct)Convert.ToUInt32(binary.Substring(26, 6), 2); break; case FormatType.Immediate: this.Rs = (RegisterType)Convert.ToUInt32(binary.Substring(6, 5), 2); this.Rt = (RegisterType)Convert.ToUInt32(binary.Substring(11, 5), 2); string immBinary = binary.Substring(16, 16); immBinary = new string(immBinary[0], 16) + immBinary; this.Immediate = Convert.ToInt32(immBinary, 2); this.ImmediateZeroExtended = this.Immediate & 0x0000ffff; break; case FormatType.Jump: this.WordAddress = Convert.ToUInt32(binary.Substring(6, 26), 2); break; } }
void RefinedCalc(double error, double a, double b, Funct function) { int n = 2 * (int)Variables["n"]; double In = Variables["In"], err = Variables["Error"]; double I2n = SimpsonCalc(a, b, function, n), del = Math.Abs(In - I2n); while (del / 15 > err) { In = I2n; n *= 2; I2n = SimpsonCalc(a, b, function, n); del = Math.Abs(In - I2n); } Variables.Add("n2", n); Variables.Add("I2n", I2n); double Error = Math.Abs(Variables["Iexact"] - I2n); Variables.Add("Error2n", Error); }
public static void Main(string[] args) { char[] suit = new char[4] { '♥', '♦', '♣', '♠' }; //массив масти int[] number = new int[] { 6, 7, 8, 9, 10, 11, 12, 13, 14 }; //масств номер карты int n = 0; // количество игроков int cardnum = 0; Karta[] deck = new Karta[36]; // колода (состоит из 36 карт) Funct func = new Funct(); do { Console.Clear(); Console.WriteLine("1 < number of players < 7"); Console.Write("Enter the number of players : "); n = Convert.ToInt32(Console.ReadLine()); }while(n < 2 || n > 6); // проверка (мин количество игроков - 2, максаимальное -6) func.CreateDeck(cardnum, deck, suit, number); //создаем колоду func.RandomSort(deck); //перетасовываем карты колоды func.ShowDeck(cardnum, deck); //вывод колоды после перетасовки Karta trump = deck[deck.Length - 1]; //козырная карта (последняя в колоде) Console.Write("Trump is : "); func.CheckCard(deck, (deck.Length - 1)); Console.WriteLine(); func.ShowPlayersCards(n, deck); //вывод карт игроков int[] summ = new int[n]; //массив состоящий из сумм карт игроков func.FindSumm(summ, deck, n, trump); //поиск максимальной суммы Console.ReadKey(); }
void FillM(int n, double a, double b, Funct f) { A[0, 0] = 1; A[n - 1, n - 1] = 1; for (int i = 1; i < n - 1; i++) { A[i, i] = 4 * h; A[i, i - 1] = h; if (i < n - 1) { A[i, i + 1] = h; } double fi0 = f(a + h * (i - 1)); double fi = f(a + h * i); double fi1 = f(a + h * (i + 1)); double s1 = (fi1 + fi) / h; double s2 = (fi - fi0) / h; B[i] = 6 * (s1 - s2); } }
public EventModify AlignRotate(Funct radiansFunc, Vector2 origin = default(Vector2)) { return(WithModifiers(new EventAlignRotate(radiansFunc, origin))); }
double Ai(double a, double b, int i, Funct f) { return(f(a + i * h)); }
public Repository(Funct <T, int> getPK) { _getPK = getPK; }
public EventModify SetAlpha(Funct value) { return(WithModifiers(new EventSetAlpha(value))); }
public EventModify AddY(Funct value) { return(WithModifiers(new EventAddY(value))); }
public EventModify ScaleY(Funct value) { return(WithModifiers(new EventScaleY(value))); }
public EventModify SetSize(Funct value) { return(WithModifiers(new EventSetSize(value))); }
public Repository(Funct<T,int> getPK) { _getPK = getPK; _previousEntries = new Dictionary<int,T>(); }
public static Cmd ToCmd(Funct funct) { return(Cmd.REG | (Cmd)funct); }