public HalfDeviation(double a, double b, Func <double, double> f) { Console.WriteLine("\n\n\nМетод деления пополам: "); var iterationNumber = Math.Ceiling(Math.Log((3 - 2) / Math.Pow(10, -5), 2) - 1); Console.WriteLine($"Итераций: {iterationNumber}"); PrintTable.PrintRow("n", "an", "xn", "bn", "f(an)", "f(xn)", "f(bn)"); double x = (a + b) / 2; double fa = 0, fx = 0, fb = 0; do { fa = f(a); fx = f(x); fb = f(b); PrintTable.PrintRow(iterationNumber, a, x, b, fa, fx, fb); if (fx == 0) { break; } a = SameSign(fa, fx) ? x : a; b = SameSign(fb, fx) ? x : b; x = (a + b) / 2; } while (iterationNumber-- > 0); Console.WriteLine($"Х є околу: {x}"); }
//Print xp table public void printTable(string username, double xpNeeded, double bonusXp, double xpMultiplier) { //Gets skill experience to desired level and sets it to a local variable Console.Clear(); PrintTable table = new PrintTable(); Console.WriteLine("Herblore Potions User = "******" Experience needed = " + xpNeeded); table.printHeader(); // level name boosts base xp bonus xp base xp item 1 2 3 4 product item 1 2 3 4 product table.printLine(1, "Attack Potion", calc.getBase(xpMultiplier, 25.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 25.0)), calc.calculateCost("249", "221", "227", "", "121"), (calc.calculateCost("249", "221", "227", "", "121")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 25.0))); table.printLine(3, "Ranging Potion", calc.getBase(xpMultiplier, 30.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 30.0)), calc.calculateCost("249", "1951", "227", "", "27506"), (calc.calculateCost("249", "1951", "227", "", "27506")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 30.0))); table.printLine(5, "Magic Potion", calc.getBase(xpMultiplier, 35.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 35.0)), calc.calculateCost("253", "1470", "227", "", "27514"), (calc.calculateCost("253", "1470", "227", "", "27514")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 35.0))); table.printLine(7, "Strength Potion", calc.getBase(xpMultiplier, 40.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 40.0)), calc.calculateCost("253", "225", "227", "", "115"), (calc.calculateCost("253", "225", "227", "", "115")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 40.0))); table.printLine(9, "Defence Potion", calc.getBase(xpMultiplier, 45.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 45.0)), calc.calculateCost("251", "948", "227", "", "133"), (calc.calculateCost("251", "948", "227", "", "133")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 45.0))); table.printLine(13, "Antipoison ", calc.getBase(xpMultiplier, 50.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 50.0)), calc.calculateCost("251", "235", "227", "", "175"), (calc.calculateCost("251", "235", "227", "", "175")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 50.0))); table.printLine(22, "Restore Potion", calc.getBase(xpMultiplier, 62.5), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 62.5)), calc.calculateCost("255", "223", "227", "", "127"), (calc.calculateCost("255", "223", "227", "", "127")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 62.5))); table.printLine(26, "Energy Potion", calc.getBase(xpMultiplier, 67.5), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 67.5)), calc.calculateCost("255", "1975", "227", "", "3010"), (calc.calculateCost("255", "1975", "227", "", "3010")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 67.5))); table.printLine(34, "Agility Potion", calc.getBase(xpMultiplier, 80.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 80.0)), calc.calculateCost("2998", "2152", "227", "", "3034"), (calc.calculateCost("2998", "2152", "227", "", "3034")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 80.0))); table.printLine(36, "Combat Potion", calc.getBase(xpMultiplier, 84.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 84.0)), calc.calculateCost("255", "9736", "227", "", "9741"), (calc.calculateCost("255", "9736", "227", "", "9741")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 84.0))); table.printLine(38, "Prayer Potion", calc.getBase(xpMultiplier, 87.5), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 87.5)), calc.calculateCost("257", "231", "227", "", "139"), (calc.calculateCost("257", "231", "227", "", "139")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 87.5))); table.printLine(40, "Summoning Potion", calc.getBase(xpMultiplier, 92), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 92)), calc.calculateCost("12172", "12109", "227", "", "12142"), (calc.calculateCost("12172", "12109", "227", "", "12142")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 92))); table.printLine(45, "Super attack", calc.getBase(xpMultiplier, 100), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 100)), calc.calculateCost("259", "221", "227", "", "145"), (calc.calculateCost("259", "221", "227", "", "145")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 100))); table.printLine(48, "Super Antipoison", calc.getBase(xpMultiplier, 106.3), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 106.3)), calc.calculateCost("259", "235", "227", "", "181"), (calc.calculateCost("259", "235", "227", "", "181")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 106.3))); table.printLine(50, "Fishing Potion", calc.getBase(xpMultiplier, 112.5), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 112.5)), calc.calculateCost("261", "231", "227", "", "151"), (calc.calculateCost("261", "231", "227", "", "151")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 112.5))); table.printLine(52, "Super Energy", calc.getBase(xpMultiplier, 117.5), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 117.5)), calc.calculateCost("261", "2970", "227", "", "3018"), (calc.calculateCost("261", "2970", "227", "", "3018")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 117.5))); table.printLine(53, "Hunter Potion", calc.getBase(xpMultiplier, 120.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 120.0)), calc.calculateCost("261", "10109", "227", "", "10000"), (calc.calculateCost("261", "10109", "227", "", "10000")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 120.0))); table.printLine(55, "Super Strength", calc.getBase(xpMultiplier, 125.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 125.0)), calc.calculateCost("263", "225", "227", "", "157"), (calc.calculateCost("263", "225", "227", "", "157")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 125.0))); table.printLine(58, "Fletching Potion", calc.getBase(xpMultiplier, 132.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 132.0)), calc.calculateCost("14854", "11525", "227", "", "14848"), (calc.calculateCost("14854", "11525", "227", "", "14848")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 132.0))); table.printFooter(); Console.ReadKey(); }
public void printTable() { //Gets skill experience to desired level and sets it to a local variable double xpNeeded = highscores.getExpNeeded(desiredLevel, "herblore", username); PrintTable table = new PrintTable(); table.printHeader(); // level name boosts base xp bonus xp base xp item 1 2 3 4 product item 1 2 3 4 product table.printLine(1, "Attack Potion", calc.getBase(xpMultiplier, 25.0), calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 25.0)), calc.calculateCost("249", "221", "227", "", "121"), (calc.calculateCost("249", "221", "227", "", "121")) * calc.getActionsNeeded(xpNeeded, bonusXp, calc.getBase(xpMultiplier, 25.0))); }
public Newton(double a, double b, double eps, Func <double, Double> f, Func <double, double> f1, Func <double, double> f2) { Console.WriteLine("\n\n\nМетод Ньютона"); Console.WriteLine($"f'({a}) = {f1(a)}"); Console.WriteLine($"f'({b}) = {f1(b)}"); double m1 = Math.Min(f1(a), f1(b)); Console.WriteLine($"m1 = min{{f'({a}); f'({b})}} = {m1}"); Console.WriteLine(); Console.WriteLine($"f''({a}) = {f2(a)}"); Console.WriteLine($"f''({b}) = {f2(b)}"); double M2 = Math.Max(f2(a), f2(b)); Console.WriteLine($"M1 = max{{f''({a}); f''({b})}} = {M2}"); double delta = Math.Sqrt(2 * m1 * eps / M2); Console.WriteLine($"Delta = {delta}"); var x = a; if (f(x) * f2(x) <= 0) { x = b; } while (f(x) * f2(x) <= 0) { x -= eps; } PrintTable.PrintRow("n", "Xn", "|Xn-X(n-1)|", "|Xn-X(n-1)| < delta"); PrintTable.PrintRow(0, x, "-", "-"); double xPrev; var i = 1; do { xPrev = x; x = xPrev - f(x) / f1(x); PrintTable.PrintRow(i, x, Math.Abs(x - xPrev), Math.Abs(x - xPrev) < delta); i++; } while (Math.Abs(x - xPrev) >= delta); Console.WriteLine($"Х є околу: {x}"); }
//打印 void UC_PrintEvent(object sender, EventArgs e) { DataTable dt = this.dgvRecord.GetBoundData(); if (dt.Rows.Count == 0) { return; } int width = this.reportPrint.PaperSize.Width - this.reportPrint.PaperMergin.Left - this.reportPrint.PaperMergin.Right; int height = this.reportPrint.PaperSize.Height - this.reportPrint.PaperMergin.Top - this.reportPrint.PaperMergin.Bottom; PrintTable table = new PrintTable(); //设定列宽度 foreach (DataGridViewColumn dgvc in this.dgvRecord.Columns) { if (dt.Columns.Contains(dgvc.Name)) { PrintColumn pc = new PrintColumn(); pc.Name = dgvc.Name; pc.Text = dgvc.HeaderText; if (this.dgvRecord.MergeColumnNames.Contains(dgvc.Name)) { pc.IsMerged = true; } else { pc.IsMerged = false; } pc.Width = dgvc.Width; table.AddColumn(pc); } } table.DataSourse = dt; //头标题 table.drawHead += new PrintTable.DrawHeadHandler(this.DrawHead); table.HasTitle = true; table.TitleHeight = 40; this.reportPrint.PrintMethod = PrintMethods.PrintReport; //ServiceStationClient.ComponentUI.FormPrint formPrint = new ServiceStationClient.ComponentUI.FormPrint(table, this.reportPrint); //formPrint.TitleFont = new Font("宋体", 11); //formPrint.Show(); }
/// <summary> /// Метод простой итерации /// </summary> /// <param name="a">Левая граница</param> /// <param name="b">Правая граница</param> /// <param name="f">Функция</param> /// <param name="f1">Первая производная</param> public SimpleIteration(double a, double b, double eps, Func <double, Double> f, Func <double, double> f1) { Console.WriteLine("\n\n\nМетод простой итерации"); // Переходим от заданого уравнения к уравнению удобному для итерирования: x = x - alpha*f(x) var M1 = Math.Max(f1(a), f1(b)); var m1 = Math.Min(f1(a), f1(b)); if (f1(a) > f1(b)) { M1 = f1(a); m1 = f1(b); Console.WriteLine($"M1 = f({a}) = {f1(a)}"); Console.WriteLine($"m1 = f({b}) = {f1(b)}"); } else { M1 = f1(b); m1 = f1(a); Console.WriteLine($"M1 = f({b}) = {f1(b)}"); Console.WriteLine($"m1 = f({a}) = {f1(a)}"); } var alpha = 2 / (M1 + m1); Console.WriteLine($"Alpha = {alpha}"); double x = a; double stopValue = Math.Abs(f(x)) / m1; int i = 0; PrintTable.PrintRow("n", "x", "|f(xn)|/m1", "epsilon", "Stop"); while (stopValue > eps) { PrintTable.PrintRow(i, x, Math.Abs(f(x)) / m1, eps, stopValue < eps); x = x - alpha * f(x); stopValue = Math.Abs(f(x)) / m1; i++; } PrintTable.PrintRow(i, x, Math.Abs(f(x)) / m1, eps, stopValue < eps); Console.WriteLine($"Х є околу: {x}"); }
private void DisplayTable(int multiplicationCount) { List <string> output = new List <string>(); for (int i = 1; i <= multiplicationCount; i++) { for (int j = 1; j <= multiplicationCount; j++) { string line = $"{i} * {j} == {i * j}"; output.Add(line); } } var pTable = new PrintTable(output); var table = pTable.GetFormattedTable(); foreach (var line in table) { Trace.WriteLine(line); } }
public Chords(double a, double b, double eps, Func <double, Double> f, Func <double, double> f1, Func <double, double> f2) { Console.WriteLine("\n\n\nМетод хорд"); Console.WriteLine($"f'({a}) = {f1(a)}"); Console.WriteLine($"f'({b}) = {f1(b)}"); var M1 = Math.Max(f1(a), f1(b)); var m1 = Math.Min(f1(a), f1(b)); Console.WriteLine($"M1 = {M1}"); Console.WriteLine($"m1 = {m1}"); var gamma = m1 * eps / (M1 - m1); Console.WriteLine($"Gamma = {gamma}"); var x = a; // while (f(x) * f2(x) >= 0) // { x = x + eps; // } PrintTable.PrintRow("n", "Xn", "|Xn-X(n-1)|", "|Xn-X(n-1)| < gamma"); PrintTable.PrintRow(0, x, "-", "-"); double prevX; int i = 1; do { prevX = x; x = prevX - f(prevX) * (3 - prevX) / (f(3) - f(prevX)); PrintTable.PrintRow(i, x, Math.Abs(x - prevX), Math.Abs(x - prevX) < gamma); i++; } while (Math.Abs(x - prevX) >= gamma); Console.WriteLine($"Х є околу: {x}"); }
public static void logTable(PrintTable table, bool visibleLines = true) { char verticalSeparator = visibleLines ? '|' : ' '; char horizontalSeparator = visibleLines ? '=' : ' '; char lineIntersectionChar = visibleLines ? '+' : ' '; string headerLine = ""; List <System.ConsoleColor> headerLineCharColors = new List <System.ConsoleColor>(); for (int col = 0; col < table.columnNames.Count; col++) { headerLine += verticalSeparator; headerLineCharColors.Add(tableFrameColor); // don't pad rightmost header if lines are not supposed to be visible if (visibleLines || col != table.columnNames.Count - 1) { string nameStr = table.columnNames[col].PadRight(table.columnWidths[col]); headerLine += nameStr; headerLineCharColors.AddRange(Enumerable.Repeat(tableHeaderColor, nameStr.Length)); } else { string paddedNameStr = table.columnNames[col]; headerLine += paddedNameStr; headerLineCharColors.AddRange(Enumerable.Repeat(tableHeaderColor, paddedNameStr.Length)); } } headerLine += verticalSeparator; headerLineCharColors.Add(tableFrameColor); internalWriteLine(headerLine, headerLineCharColors); string horizontalLine = ""; // log line if (visibleLines) { for (int col = 0; col < table.columnNames.Count; col++) { horizontalLine += lineIntersectionChar; horizontalLine += new string(horizontalSeparator, table.columnWidths[col]); if (col == table.columnNames.Count - 1) { horizontalLine += lineIntersectionChar; } } internalWriteLine(horizontalLine, tableFrameColor); } else { internalWriteLine(""); } foreach (List <string> row in table.rows) { string lineString = ""; List <System.ConsoleColor> lineCharColors = new List <System.ConsoleColor>(); for (int col = 0; col < table.columnWidths.Count; col++) { lineString += verticalSeparator; lineCharColors.Add(tableFrameColor); string tableValue = row[col].PadRight(table.columnWidths[col]); lineString += tableValue; lineCharColors.AddRange(Enumerable.Repeat(System.Console.ForegroundColor, tableValue.Length)); } lineString += verticalSeparator; lineCharColors.Add(tableFrameColor); internalWriteLine(lineString, lineCharColors); } }
public MemoryStream CreateOrderStream(Guid orderId) { MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document(); document.Info.Title = "Order Request"; document.Info.Subject = "COUNTRY OFFICE, UGANDA"; document.Info.Author = "DRC"; this.section = document.AddSection(); Image image = section.Headers.Primary.AddImage(HttpContext.Current.Server.MapPath("/Content/reports/logos-90.png")); image.LockAspectRatio = true; image.RelativeVertical = RelativeVertical.Line; image.RelativeHorizontal = RelativeHorizontal.Margin; image.Top = ShapePosition.Top; image.Left = "13cm"; image.WrapFormat.Style = WrapStyle.Through; TextFrame heading = this.section.AddTextFrame(); Paragraph tmpHeadParagraph = heading.AddParagraph("ORDER REQUEST"); tmpHeadParagraph.Format.Alignment = ParagraphAlignment.Center; heading.Top = ShapePosition.Top; heading.Width = "12.0cm"; heading.Height = "0.8cm"; TextFrame countryOfficeAddressFrame; countryOfficeAddressFrame = section.AddTextFrame(); countryOfficeAddressFrame.Height = "3.0cm"; countryOfficeAddressFrame.Width = "3.0cm"; countryOfficeAddressFrame.Left = ShapePosition.Right; countryOfficeAddressFrame.RelativeHorizontal = RelativeHorizontal.Margin; countryOfficeAddressFrame.Top = "3.7cm"; countryOfficeAddressFrame.RelativeVertical = RelativeVertical.Page; Paragraph paragraph; paragraph = countryOfficeAddressFrame.AddParagraph("DANISH REFUGEE COUNCIL"); paragraph.Format.Font.Name = "Calibri"; paragraph.Format.Font.Size = 7; paragraph.Format.SpaceAfter = 3; paragraph.AddLineBreak(); paragraph.AddText("Borgergade 10"); paragraph.AddLineBreak(); paragraph.AddText("DK-1300 Copenhagen"); paragraph.AddLineBreak(); paragraph.AddText("Denmark"); paragraph.AddLineBreak(); paragraph.AddLineBreak(); paragraph.AddFormattedText("COUNTRY OFFICE, UGANDA", TextFormat.Bold); paragraph.AddLineBreak(); paragraph.AddText("4688 Kalungi Road"); paragraph.AddLineBreak(); paragraph.AddText("Muyenga, Kampala"); paragraph = countryOfficeAddressFrame.AddParagraph("www.drc.dk"); paragraph.Format.Font.Name = "Calibri"; paragraph.Format.Font.Size = 7; paragraph.Format.Font.Color = new Color(58, 162, 213); paragraph.Format.Font.Underline = Underline.Single; paragraph.AddLineBreak(); paragraph.AddText("WWW.danishdemininggroup.dk"); List <double> sizes = new List <double>(); sizes.AddRange(new double[] { 4.0, 4.0, 4.0 }); DataTable t = this.GetTable(orderId); PrintTable printTable = new PrintTable(t, sizes); this.summaryTable = section.AddTable(); printTable.GenerateTable(this.summaryTable); heading = this.section.AddTextFrame(); heading.Top = "0.9cm"; heading.Width = Unit.FromCentimeter(14.0); tmpHeadParagraph = heading.AddParagraph("Specification/Description, Unit, Quantities, Estimated Prices & PN/BL."); tmpHeadParagraph.Format.Alignment = ParagraphAlignment.Center; heading.Height = Unit.FromCentimeter(2.0); sizes = new List <double>(); sizes.AddRange(new double[] { 1.0, 3.5, 1.0, 1.0, 2.5, 3.5, 1.0, 2.0, 2.5 }); t = this.GetDetailsTable(orderId); TableOptions options = new TableOptions(); options.FontSizeCm = 9.0; printTable = new PrintTable(t, sizes, options); Table dTable = section.AddTable(); printTable.GenerateTable(dTable); section.AddParagraph(Environment.NewLine); sizes = new List <double>(); sizes.AddRange(new double[] { 4.5, 4.5, 4.5, 4.5 }); t = this.GetTableApproval(orderId); options = new TableOptions(); options.FontSizeCm = 9.0; printTable = new PrintTable(t, sizes, options); dTable = section.AddTable(); printTable.GenerateTable(dTable); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); MemoryStream stream = new MemoryStream(); pdfRenderer.Save(stream, false); return(stream); }