public int calculateZad7(double x1, double x2, int z, AreaType areaType) { int n = 1; int indexOfFunction = 2; //funkcja kwadratowa var isCompleted = executeWithTimeLimit(() => { var singleCount = new SingleCount(x1, x2, n, areaType, indexOfFunction); while ((int)singleCount.Area % z != 0) { n++; singleCount = new SingleCount(x1, x2, n, areaType, indexOfFunction); } }); if (isCompleted) { return(n); } else { throw new TimeoutException(); } }
public double calculateZad3(double x1, double x2, AreaType areaType) { double result = 0; var isCompleted = executeWithTimeLimit(() => { SingleCount trueResult = new SingleCount(x1, x2, 0, null, 2); for (int i = 1; i <= 6; i++) { var singleCount = new SingleCount(x1, x2, (int)Math.Pow(10, i), areaType, 2); result += Math.Pow(trueResult.Area - singleCount.Area, 2); } }); if (isCompleted) { return(result / 6); } else { throw new TimeoutException(); } }
public int calculateZad8(double z, AreaType areaType) { double trueResult = Math.Sin(Math.PI / 2); double x1 = 0; double x2 = Math.PI / 2; double maxDifference = trueResult * z / 100; int n = 1; var isCompleted = executeWithTimeLimit(() => { var singleCount = new SingleCount(x1, x2, n, areaType, (x) => Math.Cos(x)); while (Math.Abs(singleCount.Area - trueResult) >= maxDifference) { n++; singleCount = new SingleCount(x1, x2, n, areaType, (x) => Math.Cos(x)); } }); if (isCompleted) { return(n); } else { throw new TimeoutException(); } }
public Exercise6() : base("6") { sc = new SingleCount(0, 0, functionCube); sc2 = new SingleCount(0, 0, functionSquare); textBoxM = addParameter("m", 10); textBoxK = addParameter("k", 3); }
public Global calculateZad1(int m, double z) { List <SingleCount> singleCounts = new List <SingleCount>(); var isCompleted = executeWithTimeLimit(() => { for (int i = 0; i < m; i++) { SingleCount rectangle = new SingleCount(0, 100, random.Next(10, 1000000), AreaType.Rectangle, 2); SingleCount trapezoid = new SingleCount(0, 100, random.Next(10, 1000000), AreaType.Trapezoid, 2); SingleCount trueResult = new SingleCount(0, 100, random.Next(10, 1000000), null, 2); double maxDifference = trueResult.Area * z / 100; if (Math.Abs(trueResult.Area - rectangle.Area) <= maxDifference) { singleCounts.Add(rectangle); } if (Math.Abs(trueResult.Area - trapezoid.Area) <= maxDifference) { singleCounts.Add(trapezoid); } } }); if (isCompleted) { return(new Global(singleCounts)); } else { throw new TimeoutException(); } }
public int calculateZad2(double z) { int i = 1; var isCompleted = executeWithTimeLimit(() => { List <SingleCount> singleCounts = new List <SingleCount>(); SingleCount trueResult = new SingleCount(0, 100, 0, null, 3); double maxDifference = trueResult.Area * z / 100; SingleCount rectangle = new SingleCount(0, 100, i, AreaType.Rectangle, 3); SingleCount trapezoid = new SingleCount(0, 100, i, AreaType.Trapezoid, 3); while ((Math.Abs(trueResult.Area - rectangle.Area) >= maxDifference) || (Math.Abs(trueResult.Area - rectangle.Area) >= maxDifference)) { rectangle = new SingleCount(0, 100, i, AreaType.Rectangle, 3); trapezoid = new SingleCount(0, 100, i, AreaType.Trapezoid, 3); i++; } }); if (isCompleted) { return(i); } else { throw new TimeoutException(); } }
public Exercise4() : base("4") { this.sc = new SingleCount(0, 0, functionCube); textBoxK = addParameter("k", 4); textBoxZ = addParameter("z", 13); textBoxX1 = addParameter("x1", 0); textBoxX2 = addParameter("x2", 100); }
public Exercise7() : base("7") { this.sc = new SingleCount(0, 100, functionSquare); textBoxX1 = addParameter("x1", 0); textBoxX2 = addParameter("x2", 100); textBoxZ = addParameter("z", 2); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.TextLength == 0 || textBox2.TextLength == 0 || textBox3.TextLength == 0) { MessageBox.Show("Some textboxes are empty! Try again."); return; } double parsedValue; double parsedValue1; double parsedValue2; if (!double.TryParse(textBox1.Text, out parsedValue)) { MessageBox.Show("This is double only fields! Try again"); return; } if (!double.TryParse(textBox2.Text, out parsedValue1)) { MessageBox.Show("This is double only fields! Try again"); return; } if (!double.TryParse(textBox3.Text, out parsedValue2)) { MessageBox.Show("This is double only fields! Try again"); return; } this.listBox1.Items.Clear(); double x1 = double.Parse(this.textBox1.Text); double x2 = double.Parse(this.textBox2.Text); double z = double.Parse(this.textBox3.Text); if (z < 0 || z > 1000) { MessageBox.Show("Please enter value z from 0 to 1000"); return; } if (x1 < 0 || x1 > 1000) { MessageBox.Show("Please enter value x1 from 0 to 1000"); return; } if (x2 < 0 || x2 > 1000) { MessageBox.Show("Please enter value x2 from 0 to 1000"); return; } SingleCount singleCount = new SingleCount(x1, x2, function, AreaType.Rectangle, z); double n = singleCount.Zad7(); this.listBox1.Items.Add($"Metoda prostokątna: {n}"); singleCount.AreaType = AreaType.Trapezoid; double n1 = singleCount.Zad7(); this.listBox1.Items.Add($"Metoda trapezowa: {n1}"); }
private void button1_Click_1(object sender, EventArgs e) { if (textBox1.TextLength == 0 || textBox2.TextLength == 0) { MessageBox.Show("Some textboxes are empty! Try again."); return; } int parsedValue; double parsedValue1; if (!int.TryParse(textBox1.Text, out parsedValue)) { MessageBox.Show("This is int only fields! Try again"); return; } if (!double.TryParse(textBox2.Text, out parsedValue1)) { MessageBox.Show("This is double only fields! Try again"); return; } int m = int.Parse(this.textBox1.Text); double z = double.Parse(this.textBox2.Text); if (m <= 0 || m > 1000) { MessageBox.Show("m range from 1 to 1000"); return; } if (z < 0 || z > 100) { MessageBox.Show("z range from 0 to 100"); return; } int x1 = 0; double x2 = 100; double real_result = 1000000 / 3; this.listBox1.Items.Clear(); SingleCount singleCount = new SingleCount(x1, x2, m, 10, 100000, function, real_result, AreaType.Rectangle, z); List <double> listRect = singleCount.Zad1(); foreach (var area in listRect) { this.listBox1.Items.Add($"Metoda prostokatna: {area}"); } singleCount.AreaType = AreaType.Trapezoid; List <double> listTrap = singleCount.Zad1(); foreach (var area in listTrap) { this.listBox1.Items.Add($"Metoda trapezowa: {area}"); } }
private void button1_Click(object sender, EventArgs e) { var valM = textBox1.Text; var valZ = textBox2.Text; var correct_result = 333333.333333; SingleCount exercise1 = new SingleCount(); Random random = new Random(); exercise1.X1 = 0; exercise1.X2 = 100; int m; double z; bool parseSuccess1 = int.TryParse(valM, out m); bool parseSuccess2 = double.TryParse(valZ, out z); // Percentage error from 0 to 100 if (parseSuccess1 && parseSuccess2) { Wynik.Items.Clear(); if (z >= 0 && z <= 100 && m >= 1 && m <= 1000) { exercise1.CalculationNumber = m; double percentVal = z * correct_result / 100; // Value of percentage error double maxAccVal = correct_result + percentVal; // Maximal accepted value double minAccVal = correct_result - percentVal; // Minimal accepted value for (int i = 0; i < exercise1.CalculationNumber; ++i) { exercise1.N = random.Next(10, 100000); var result_trap = exercise1.TrapezoidMethod(exercise1.FUNX2); var result_rec = exercise1.RectangleMethod(exercise1.FUNX2); if (result_trap >= minAccVal && result_trap <= maxAccVal) { Wynik.Items.Add("Trapezoid method: " + result_trap); } if (result_rec >= minAccVal && result_rec <= maxAccVal) { Wynik.Items.Add("Rectangle method: " + result_rec); } } Wynik.Items.Add("END OF CALCULATION"); } else { Wynik.Items.Add("Please change value of Z or M"); Wynik.Items.Add("The valid values are:"); Wynik.Items.Add("M range 1 1000"); Wynik.Items.Add("Z range 0 100"); } } else { Wynik.Items.Add("The given data was invalid"); } }
public List <double> calculateZad5(int k, AreaType areaType) { double x1 = 0; double x2 = 10; double x3 = 5; double x4 = 6; var isCompleted = executeWithTimeLimit(() => { var resultFor3 = new SingleCount(x1, x2, k, areaType, 3); int n = (int)Math.Pow(10, k); var resultFor2 = new SingleCount(x3, x4, n, areaType, 2); while (resultFor2.Area < resultFor3.Area) { x4++; resultFor2 = new SingleCount(x3, x4, n, areaType, 2); } double addOrSubstract = 0.5d; int toleratedNumberOfIterations = 1000; while ((resultFor2.Area != resultFor3.Area) && toleratedNumberOfIterations != 0) { if (resultFor2.Area < resultFor3.Area) { x4 += addOrSubstract; } else { x4 -= addOrSubstract; } resultFor2 = new SingleCount(x3, x4, n, areaType, 2); addOrSubstract /= 2; toleratedNumberOfIterations--; } }); if (isCompleted) { return(new List <double>() { x1, x2, x3, x4 }); } else { throw new TimeoutException(); } }
public bool calculateZad4(double x1, double x2, int k, double z, AreaType areaType) { SingleCount singleCount = null; var isCompleted = executeWithTimeLimit(() => { singleCount = new SingleCount(x1, x2, (int)Math.Pow(10, k), areaType, 3); }); if (isCompleted) { return(((int)singleCount.Area % z) == 0); } else { throw new TimeoutException(); } }
private void button1_Click(object sender, EventArgs e) { this.listBox1.Items.Clear(); SingleCount singleCount = new SingleCount(0, 100, Convert.ToInt32(this.textM.Text), 10, 100000, function, 1000000 / 3, AreaType.Rectangle, Convert.ToDouble(this.textZ.Text)); List <double> listRect = singleCount.Zad1(); foreach (var area in listRect) { this.listBox1.Items.Add($"Metoda prostokatna: {area}"); } singleCount.AreaType = AreaType.Trapezoid; List <double> listTrap = singleCount.Zad1(); foreach (var area in listTrap) { this.listBox1.Items.Add($"Metoda trapezowa: {area}"); } }
private void CALCULATE_Click(object sender, EventArgs e) { var correct_result = 333333.333333; SingleCount exercise3 = new SingleCount(); exercise3.X1 = 0; exercise3.X2 = 100; for (int i = 1; i < 7; ++i) { exercise3.N = (int)Math.Pow(10, i); Wynik.Items.Add("For n: " + exercise3.N); var result_trap = exercise3.TrapezoidMethod(exercise3.FUNX2); exercise3.MinSquareError = Math.Pow(correct_result - result_trap, 2); Wynik.Items.Add("Trapezoid method: " + exercise3.MinSquareError); var result_rec = exercise3.RectangleMethod(exercise3.FUNX2); exercise3.MinSquareError = Math.Pow(correct_result - result_rec, 2); Wynik.Items.Add("Rectangle method: " + exercise3.MinSquareError); } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.TextLength == 0) { MessageBox.Show("Some textboxes are empty! Try again."); return; } double parsedValue; if (!double.TryParse(textBox1.Text, out parsedValue)) { MessageBox.Show("This is double only fields! Try again"); return; } double z = double.Parse(this.textBox1.Text); if (z > 65 || z < 0) { MessageBox.Show("Please enter value from 0 to 65"); return; } int lowestH = 0; int highestH = 100; double real_result = 25000000; this.listBox1.Items.Clear(); SingleCount singleCount = new SingleCount(function, real_result, AreaType.Rectangle, z, lowestH, highestH); double n_rect = singleCount.Zad2(); this.listBox1.Items.Add($"Metoda prostokatna: {n_rect}"); singleCount.AreaType = AreaType.Trapezoid; double n_trap = singleCount.Zad2(); this.listBox1.Items.Add($"Metoda trapezowa: {n_trap}"); }
public Global calculateZad6(int k, int m, AreaType areaType) { int n = (int)Math.Pow(10, k); double currentLowestDifference = double.MaxValue; SingleCount currentBestForX2 = null; SingleCount currentBestForX3 = null; var isCompleted = executeWithTimeLimit(() => { for (int i = 0; i < m; i++) { int x1 = random.Next(); int x2 = random.Next(x1, int.MaxValue); int x3 = random.Next(); int x4 = random.Next(x3, int.MaxValue); var singleCount2 = new SingleCount(x1, x2, n, areaType, 2); var singleCount3 = new SingleCount(x3, x4, n, areaType, 3); double diff = Math.Abs(singleCount2.Area - singleCount3.Area); if (diff < currentLowestDifference) { currentLowestDifference = diff; currentBestForX2 = singleCount2; currentBestForX3 = singleCount3; } } }); if (isCompleted) { return(new Global(new List <SingleCount>() { currentBestForX2, currentBestForX3 })); } else { throw new TimeoutException(); } }
private double integralX(SingleCount exercise5, bool method, Func <double, double> fun, Random random) { exercise5.X1 = 0; while (true) { exercise5.X2 = findX(random); if (exercise5.X2 > exercise5.X1) { break; } } double local_x = 0; if (method) // Trapezoid { local_x = exercise5.TrapezoidMethod(fun); } else { local_x = exercise5.RectangleMethod(fun); } return(local_x); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.TextLength == 0 || textBox2.TextLength == 0) { MessageBox.Show("Some textboxes are empty! Try again."); return; } int parsedValue; int parsedValue1; if (!int.TryParse(textBox1.Text, out parsedValue)) { MessageBox.Show("This is int only fields! Try again"); return; } if (!int.TryParse(textBox2.Text, out parsedValue1)) { MessageBox.Show("This is int only fields! Try again"); return; } int x1 = int.Parse(this.textBox1.Text); int x2 = int.Parse(this.textBox2.Text); double real_result = 99999999 / 4; this.listBox1.Items.Clear(); SingleCount singleCount = new SingleCount(real_result, x1, x2, function, AreaType.Rectangle); double result_rect = singleCount.Zad3(); singleCount.AreaType = AreaType.Trapezoid; double result_trap = singleCount.Zad3(); this.listBox1.Items.Add($"Metoda prostokatna: {result_rect}"); this.listBox1.Items.Add($"Metoda trapezoida: {result_trap}"); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.TextLength == 0) { MessageBox.Show("Some textboxes are empty! Try again."); return; } double parsedValue; if (!double.TryParse(textBox1.Text, out parsedValue)) { MessageBox.Show("This is double only fields! Try again"); return; } double z = double.Parse(this.textBox1.Text); if (z < 0 || z > 100) { MessageBox.Show("Please enter value z from 0 to 100"); return; } int lowestH = 0; double real_result = 1; this.listBox1.Items.Clear(); SingleCount singleCount = new SingleCount(Math.Cos, real_result, AreaType.Rectangle, z, 0, (int)Math.PI / 2); double listRect = singleCount.Zad2(); this.listBox1.Items.Add($"Metoda prostokatna: {listRect}"); singleCount.AreaType = AreaType.Trapezoid; double listTrap = singleCount.Zad2(); this.listBox1.Items.Add($"Metoda trapezowa: {listTrap}"); }
private void CALCULATE_Click(object sender, EventArgs e) { var valK = textBox3.Text; SingleCount exercise5 = new SingleCount(); Random random = new Random(); int K; bool parseSuccess1 = int.TryParse(valK, out K); if (parseSuccess1) { Wynik.Items.Clear(); if (K >= 0 && K <= 4) { exercise5.N = (int)Math.Pow(10, K); double local_x2, local_x3; bool flag = false; for (int i = 1; i < 25000; ++i) { local_x2 = integralX(exercise5, true, exercise5.FUNX2, random); local_x3 = integralX(exercise5, true, exercise5.FUNX3, random); if (local_x2 == local_x3) { Wynik.Items.Add("Trapezoid method: " + local_x2); flag = true; } } if (!flag) { Wynik.Items.Add("K: " + K); Wynik.Items.Add("No matches for Trapezoid method.."); } flag = false; for (int i = 1; i < 25000; ++i) { local_x2 = integralX(exercise5, false, exercise5.FUNX2, random); local_x3 = integralX(exercise5, false, exercise5.FUNX3, random); if (local_x2 == local_x3) { Wynik.Items.Add("Rectangle method: " + local_x2); flag = true; } } if (!flag) { Wynik.Items.Add("K: " + K); Wynik.Items.Add("No matches for Rectangle method.."); } } else { Wynik.Items.Add("Please change value of K"); Wynik.Items.Add("The valid values is:"); Wynik.Items.Add("K range 0 4"); } } else { Wynik.Items.Add("The given data was invalid"); } }
private void oblicz1_Click(object sender, EventArgs e) { try { String s = textBox1.Text; double k = Convert.ToDouble(s); double wynik = 1, w1 = 0, w2 = 0; int x1p, x2p, x1t, x2t, t; SingleCount min1p = new SingleCount(); SingleCount min2p = new SingleCount(); SingleCount min1t = new SingleCount(); SingleCount min2t = new SingleCount(); if (k > 5) { throw new Exception("Podaj liczbę 'k' mniejszą od 6"); } int n = 10; for (int i = 0; i < k; i++) { n = n * 10; } do { x1p = losuj(); Thread.Sleep(1); x2p = losuj(); while (x1p == x2p) { x2p = losuj(); } Thread.Sleep(10); x1t = losuj(); Thread.Sleep(1); x2t = losuj(); while (x1t == x2t) { x2t = losuj(); } if (x1p > x2p) { t = x2p; x2p = x1p; x1p = t; } if (x1t > x2t) { t = x2t; x2t = x1t; x1t = t; } if (x1p != x1t) { wynik = w1 - w2; w1 = mProstokatow(x1p, x2p, n, 1); w2 = mProstokatow(x1t, x2t, n, 2); } if (wynik == 0 && x1p != x1t) { min1t = new SingleCount(x1p, x2p, 1000, AreaType.Rectangle, 0, w1); min2t = new SingleCount(x1t, x2t, 1000, AreaType.Rectangle, 0, w2); } } while(wynik == 0); textBox2.Text = ("Dla metody prostokątna wynosi obie całki dla różnych funkcji są równe dla wartości: " + " x1:" + min1t.x1.ToString() + " ,x2:" + min1t.x2.ToString() + " \n x1:" + min2t.x1.ToString() + " ,x2:" + min2t.x2.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void CALCULATE_Click(object sender, EventArgs e) { var valZ = textBox1.Text; var correct_result = 1; SingleCount exercise8 = new SingleCount(); exercise8.X1 = 0; exercise8.X2 = Math.PI / 2; double z; bool parseSuccess1 = double.TryParse(valZ, out z); // Percentage error from 0 to 100 if (parseSuccess1) { Wynik.Items.Clear(); if (z >= 0 && z <= 100) { double percentVal = z * correct_result / 100; // Value of percentage error double maxAccVal = correct_result + percentVal; // Maximal accepted value double minAccVal = correct_result - percentVal; // Minimal accepted value bool flag = false; for (int i = 1; i < 25000; ++i) { exercise8.N = i; var result_trap = exercise8.TrapezoidMethod(exercise8.FUNCOSX); if (result_trap >= minAccVal && result_trap <= maxAccVal) { Wynik.Items.Add("Trapezoid method: " + result_trap); Wynik.Items.Add("For n: " + exercise8.N); flag = true; break; } } if (!flag) { Wynik.Items.Add("No matches for Trapezoid method.."); } flag = false; for (int i = 1; i < 25000; ++i) { exercise8.N = i; var result_rec = exercise8.RectangleMethod(exercise8.FUNCOSX); if (result_rec >= minAccVal && result_rec <= maxAccVal) { Wynik.Items.Add("Rectangle method: " + result_rec); Wynik.Items.Add("For n: " + exercise8.N); flag = true; break; } } if (!flag) { Wynik.Items.Add("No matches for Rectangle method.."); } } else { Wynik.Items.Add("Please change value of Z"); Wynik.Items.Add("The valid values are:"); Wynik.Items.Add("Z range 0 100"); } } else { Wynik.Items.Add("The given data was invalid"); } }
private void button1_Click(object sender, EventArgs e) { float true_wynik = 1000000 / 3; int z = int.Parse(z_box.Text); Random rnd = new Random(); double f = 0.0F; int o = 0; WindowsFormsApp.SingleCount single = new SingleCount(); bool czy1 = false; bool czy2 = false; single.X1 = double.Parse(x1_box.Text); single.X2 = double.Parse(x2_box.Text); for (double j = 10; j < 100000; j = j + 1) { f = 0.0F; int licz = 0; double old_i = 0; double n = j; for (double i = single.X1; i <= single.X2; i = i + 100F / n) { licz += 1; f += (i * i) * (i - old_i); old_i = i; } ; if (Math.Floor(f) % z == 0) { Console.Out.WriteLine("wartosc f = " + f.ToString() + " "); wynik_box.Text += " prostokaty n = " + n.ToString(); czy1 = true; } f = 0.0F; n = j; old_i = 0; for (double i = single.X1; i <= single.X2; i = i + 100F / n) { licz += 1; f += (((i * i) + (old_i * old_i)) / 2) * (i - old_i); old_i = i; } ; if (Math.Floor(f) % z == 0) { wynik_box.Text += " trapezy n = " + n.ToString(); czy2 = true; } if (czy1 && czy2) { break; } } ; }
private void CALCULATE_Click(object sender, EventArgs e) { var valZ = textBox1.Text; var valx1 = textBox2.Text; var valx2 = textBox3.Text; SingleCount exercise7 = new SingleCount(); double x1, x2; int Z; bool parseSuccess1 = double.TryParse(valx1, out x1); bool parseSuccess2 = double.TryParse(valx2, out x2); bool parseSuccess3 = int.TryParse(valZ, out Z); if (parseSuccess1 && parseSuccess2 && parseSuccess3) { Wynik.Items.Clear(); if (x1 >= 0 && x1 <= 1000 && x2 >= 0 && x2 <= 1000 && x2 > x1 && Z > 0 && Z <= 1000) { exercise7.X1 = x1; exercise7.X2 = x2; bool flag = false; for (int i = 2; i < 25000; ++i) { exercise7.N = i; var result_trap = exercise7.TrapezoidMethod(exercise7.FUNX2); if (result_trap % Z == 0) { Wynik.Items.Add("Trapezoid method: " + result_trap); Wynik.Items.Add("For n: " + exercise7.N); flag = true; break; } } if (!flag) { Wynik.Items.Add("No matches for Trapezoid method.."); } flag = false; for (int i = 2; i < 25000; ++i) { exercise7.N = i; var result_rec = exercise7.RectangleMethod(exercise7.FUNX2); if (result_rec % Z == 0) { Wynik.Items.Add("Rectangle method: " + result_rec); Wynik.Items.Add("For n: " + exercise7.N); flag = true; break; } } if (!flag) { Wynik.Items.Add("No matches for Rectangle method.."); } } else { Wynik.Items.Add("Please change value of X1 or X1 or Z"); Wynik.Items.Add("The valid values are:"); Wynik.Items.Add("X1 range 0 1000"); Wynik.Items.Add("X2 range 0 1000"); Wynik.Items.Add("Z range >0 1000"); Wynik.Items.Add("X2 > X1"); } } else { Wynik.Items.Add("The given data was invalid"); } }
private void oblicz1_Click(object sender, EventArgs e) { try { String s = textBox1.Text; int k = Convert.ToInt16(s); s = textBox2.Text; int m = Convert.ToInt16(s); int n = 10; double wynik1, wynik2; double MIN1 = Double.MaxValue; double MIN2 = Double.MaxValue; SingleCount min1p = new SingleCount(); SingleCount min2p = new SingleCount(); SingleCount min1t = new SingleCount(); SingleCount min2t = new SingleCount(); if (k > 5) { throw new Exception("Podaj liczbę 'k' mniejszą od 6"); } else if (m > 100) { throw new Exception("Podaj liczbę 'm' mniejszą od 100"); } for (int i = 1; i < k; i++) { n = n * 10; } int[,] tablica1 = new int[2, m]; int[,] tablica2 = new int[2, m]; int a, b, a2, b2; for (int i = 0; i < m; i++) { a = losuj(); Thread.Sleep(1); b = losuj(); while (a == b) { b = losuj(); } a2 = losuj(); Thread.Sleep(1); b2 = losuj(); while (a2 == b2) { b2 = losuj(); } if (a > b) { tablica1[0, i] = b; tablica1[1, i] = a; } else if (a <= b) { tablica1[0, i] = a; tablica1[1, i] = b; } if (a2 > b2) { tablica2[0, i] = b2; tablica2[1, i] = a2; } else if (a2 >= b2) { tablica2[0, i] = a2; tablica2[1, i] = b2; } } List <SingleCount> listaP = new List <SingleCount>(); for (int i = 0; i < m; i++) { wynik1 = mProstokatow(tablica1[0, i], tablica1[1, i], n, 1); wynik2 = mProstokatow(tablica2[0, i], tablica2[1, i], n, 2); if (MIN1 > Math.Abs(wynik1 - wynik2)) { min1p = new SingleCount(tablica1[0, i], tablica1[1, i], 1000, AreaType.Trapezoid, 0, wynik1); min2p = new SingleCount(tablica2[0, i], tablica2[1, i], 1000, AreaType.Trapezoid, 0, wynik2); MIN1 = Math.Abs(wynik1 - wynik2); } wynik1 = mTrapezow(tablica1[0, i], tablica1[1, i], n, 1); wynik2 = mTrapezow(tablica2[0, i], tablica2[1, i], n, 2); if (MIN2 > Math.Abs(wynik1 - wynik2)) { min1t = new SingleCount(tablica1[0, i], tablica1[1, i], 1000, AreaType.Trapezoid, 0, wynik1); min2t = new SingleCount(tablica2[0, i], tablica2[1, i], 1000, AreaType.Trapezoid, 0, wynik2); MIN2 = Math.Abs(wynik1 - wynik2); } } textBox3.Text = ("Najmniejsza różnica dla metody prostokątna wynosi: " + MIN1 + " wynik1:" + min1p.calculationNumber.ToString() + " ,wynik2:" + min2p.calculationNumber.ToString() + "\n \n Najmniejsza różnica dla metody trapezowej wynosi: " + MIN2 + " wynik1:" + min1t.calculationNumber.ToString() + " ,wynik2:" + min2t.calculationNumber.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void oblicz1_Click(object sender, EventArgs e) { Global g; SingleCount sc; String s; int m = 10; try { s = textBox1.Text; m = Convert.ToInt16(s); if (m > 100) { throw new Exception("Podaj liczbę 'm' mniejszą od 100"); } else { s = textBox2.Text; double z = Convert.ToDouble(s); int n = losuj(); double calkaPT = mTrapezow(0, 100, n); double calkaPP = mProstokatow(0, 100, n); double area = Math.Abs(calkaPT % z); double wynik; List <SingleCount> listaP = new List <SingleCount>(); for (int i = 0; i < m; i++) { n = losuj(); wynik = mTrapezow(0, 100, n); sc = new SingleCount(0, 100, n, AreaType.Trapezoid, area, wynik); if (wynik <= calkaPT + area && wynik >= calkaPT - area) { listaP.Add(sc); } } for (int i = 0; i < m; i++) { n = losuj(); wynik = mProstokatow(0, 100, n); sc = new SingleCount(0, 100, n, AreaType.Rectangle, area, wynik); if (wynik <= calkaPP + area && wynik >= calkaPP - area) { listaP.Add(sc); } } g = new Global(listaP); for (int i = 0; i < g.ListOfSingleCount.Count; i++) { listBox1.Items.Add("Wynik: " + g.ListOfSingleCount[i].calculationNumber.ToString() + " , metoda: " + g.ListOfSingleCount[i].areaType.ToString()); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { int z = int.Parse(z_box.Text); Random rnd = new Random(); int d = 10; int l = 100000; double f = 0.0F; int o = 0; WindowsFormsApp.SingleCount single = new SingleCount(); single.X1 = 0; single.X2 = Math.PI / 2; single.Area = Math.Sin(single.X2) - Math.Sin(single.X1); bool czy1 = false; bool czy2 = false; for (double n = 100000.0F; n > 0; n -= Math.Max(n * 0.1, 10)) { f = 0.0F; int licz = 0; double old_i = 0.0F; for (double i = single.X1; i <= single.X2; i = i + 100F / n) { licz += 1; f += Math.Cos(i) * (i - old_i); old_i = i; } ; if ((Math.Abs(single.Area - f) / single.Area >= z / 100.0) && !czy1) { string wynik = "metoda prostokatów parametry to n="; wynik += n.ToString(); wynik += " wynik to ="; wynik += f.ToString(); wynik += "\t\t\t"; wynik_box.Text += wynik; czy1 = true; } f = 0.0F; old_i = 0.0F; for (double i = single.X1; i <= single.X2; i = i + 100F / n) { licz += 1; f += ((Math.Cos(i) + Math.Cos(old_i)) / 2) * (i - old_i); old_i = i; } ; if ((Math.Abs(single.Area - f) / single.Area >= z / 100.0) && !czy2) { double xxx = f; string wynik = "metoda trapezów parametry to n="; wynik += n.ToString(); wynik += " wynik to ="; wynik += f.ToString(); wynik += "\t\t"; wynik_box.Text += wynik; czy2 = true; } if (czy1 && czy2) { break; } } ; }
public Exercise8() : base("8") { this.sc = new SingleCount(0, 100, f); textBoxZ = addParameter("z", 0); }
public Exercise1() : base("1") { this.sc = new SingleCount(0, 100, functionSquare); this.textBoxM = addParameter("m", 10); this.textBoxZ = addParameter("z", 5); }