Advertisement
Guest User

Untitled

a guest
May 30th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace ЧМ_2_4_семестр_на_сишарпе
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public double[,] mass = new double [12,12];
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. double func(double x)
  21. {
  22. return Math.Tan(Math.Pow(x, 3));
  23. }
  24. void calc(double a1,double step,double [,] x)
  25. { double a=a1;
  26. int temp=10;
  27. for (int i = 0; i < 11;i++ )
  28. {
  29. x[0, i] = a;
  30. a += step;
  31. dataGridView1.Rows[i].Cells[0].Value = Convert.ToString(x[0, i]);
  32. x[1,i]=func(x[0, i]);
  33. dataGridView1.Rows[i].Cells[1].Value = Convert.ToString(x[1, i]);
  34. }
  35. for (int i = 2; i < 12; i++)
  36. {
  37.  
  38. for (int j = 0; j <temp; j++)
  39. {
  40. x[i, j] = x[i-1,j+1] - x[i-1,j];
  41. dataGridView1.Rows[j].Cells[i].Value = Convert.ToString(Math.Round(x[i, j],15));
  42.  
  43. }
  44. temp--;
  45. }
  46. }
  47. double polynom(double[,] x, double xi, double h, bool fl)
  48. {
  49. double p = 1;
  50. double q;
  51. double y;
  52. if (fl == true)
  53. {
  54. q = (xi - x[0, x.GetLength(0) - 2])/h;
  55. y = x[1, x.GetLength(0) - 2];
  56. }
  57. else
  58. {
  59. q = (xi - x[0, 0]) / h;
  60. y = x[1, 0];
  61. }
  62. int j = 3;
  63. double factorial = 1;
  64. for(int i = 2; i < 12; i++)
  65. {
  66. factorial *= i - 1;
  67. if (fl == true)
  68. {
  69. p *= q + i - 2;
  70. y += (p / factorial) * x[i, x.GetLength(0) - j];
  71. j++;
  72. }
  73. else
  74. {
  75. p *= q - i + 2;
  76. y += (p / factorial) * x[i, 0];
  77. }
  78. }
  79. return y;
  80. }
  81. private void Form1_Load(object sender, EventArgs e)
  82. {
  83. dataGridView1.RowCount = 11;
  84. dataGridView1.ColumnCount = 12;
  85. calc(0, 0.05, mass);
  86. polynom(mass, -0.0125, 0.05, false);
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement