@@ -52,14 +52,27 @@ void MethodMonteKarlo::InteractionForm::fillTable_values(const int& N, std::vect
5252
5353System::Void MethodMonteKarlo::InteractionForm::Chart1_MouseClick (System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
5454{
55- double coordX = int ((chart1->ChartAreas [0 ]->AxisX ->PixelPositionToValue ((double )e->X )) * 1000 + 0.5 ) / 1000.0 ;
56- double coordY = int ((chart1->ChartAreas [0 ]->AxisY ->PixelPositionToValue ((double )e->Y )) * 1000 + 0.5 ) / 1000.0 ;
57- label_X->Text = " X: " + coordX.ToString ();
58- label_Y->Text = " Y: " + coordY.ToString ();
59- coordX = int ((chart1->ChartAreas [1 ]->AxisX ->PixelPositionToValue ((double )e->X )) * 1000 + 0.5 ) / 1000.0 ;
60- coordY = int ((chart1->ChartAreas [1 ]->AxisY ->PixelPositionToValue ((double )e->Y )) * 1000 + 0.5 ) / 1000.0 ;
61- label_X2->Text = " X: " + coordX.ToString ();
62- label_Y2->Text = " Y: " + coordY.ToString ();
55+ int minX1, minY1, maxX1, maxY1;
56+ minX1 = (int )chart1->ChartAreas [0 ]->Position ->X ;
57+ maxX1 = (int )(chart1->ChartAreas [0 ]->Position ->X + chart1->ChartAreas [0 ]->Position ->Width * chart1->Width / 100 );
58+ minY1 = (int )chart1->ChartAreas [0 ]->Position ->Y ;
59+ maxY1 = (int )(chart1->ChartAreas [0 ]->Position ->Y + chart1->ChartAreas [0 ]->Position ->Height * chart1->Height / 100 );
60+ Point posChart (e->X , e->Y ); // Position of the mouse respect to the chart
61+
62+ if (posChart.X >= minX1 && posChart.X <= maxX1 && posChart.Y >= minY1 && posChart.Y <= maxY1)
63+ {
64+ double coordX = int ((chart1->ChartAreas [0 ]->AxisX ->PixelPositionToValue ((double )e->X )) * 1000 + 0.5 ) / 1000.0 ;
65+ double coordY = int ((chart1->ChartAreas [0 ]->AxisY ->PixelPositionToValue ((double )e->Y )) * 1000 + 0.5 ) / 1000.0 ;
66+ label_X->Text = " X: " + coordX.ToString ();
67+ label_Y->Text = " Y: " + coordY.ToString ();
68+ }
69+ else
70+ {
71+ double coordX = int ((chart1->ChartAreas [1 ]->AxisX ->PixelPositionToValue ((double )e->X )) * 1000 + 0.5 ) / 1000.0 ;
72+ double coordY = int ((chart1->ChartAreas [1 ]->AxisY ->PixelPositionToValue ((double )e->Y )) * 1000 + 0.5 ) / 1000.0 ;
73+ label_X2->Text = " X: " + coordX.ToString ();
74+ label_Y2->Text = " Y: " + coordY.ToString ();
75+ }
6376}
6477
6578
@@ -137,6 +150,7 @@ System::Void MethodMonteKarlo::InteractionForm::Btn_squareTringle(System::Object
137150}
138151
139152
153+
140154System::Void MethodMonteKarlo::InteractionForm::Btn_squareIntegral_Click (System::Object^ sender, System::EventArgs^ e)
141155{
142156 clearInteractiveElementChartArea2 ();
@@ -148,7 +162,8 @@ System::Void MethodMonteKarlo::InteractionForm::Btn_squareIntegral_Click(System:
148162 this ->table_values_integral ->ColumnCount = 20 ;
149163
150164 std::vector<double > x_integral;
151- std::vector<double > y_integral;
165+ std::vector<double > y_integral;
166+
152167 getCoordinateMonteCarloIntegral (x_integral, y_integral,numVar,N);
153168 double minFunc = 0 , maxFunc = 0 ;
154169 findMax_MinFuncMonteCarlo (y_integral, maxFunc, minFunc);
@@ -165,7 +180,7 @@ System::Void MethodMonteKarlo::InteractionForm::Btn_squareIntegral_Click(System:
165180 }
166181 this ->chart1 ->Series [4 ]->Points ->AddXY (x_integral[x_integral.size ()-1 ], y_integral[y_integral.size ()-1 ]);
167182
168- const double a = 5 ;
183+ const double a = 5.0 ;
169184 const double b = maxFunc;
170185 tb_a_int->Text = a.ToString ();
171186 tb_b_int->Text = b.ToString ();
@@ -176,9 +191,11 @@ System::Void MethodMonteKarlo::InteractionForm::Btn_squareIntegral_Click(System:
176191 fillTable_values (N,rnd_x, rnd_y,this ->table_values_integral );
177192 int M = 0 ;
178193
194+ double totalSum = 0 ;
179195 for (int i = 0 ; i < N; i++)
180196 {
181- double f_xi = functionIntegral (rnd_x[i],numVar);
197+ double f_xi =functionIntegral (rnd_x[i],numVar);
198+ totalSum += f_xi;
182199 if (N<100 )
183200 this ->table_values_integral ->Rows [4 ]->Cells [i]->Value = f_xi;
184201 if (rnd_y[i] < f_xi && rnd_x[i] <= x_integral[x_integral.size ()-1 ])
@@ -189,13 +206,9 @@ System::Void MethodMonteKarlo::InteractionForm::Btn_squareIntegral_Click(System:
189206 else
190207 this ->chart1 ->Series [6 ]->Points ->AddXY (rnd_x[i], rnd_y[i]);
191208 }
192- double integral = (M * a * b) / N;// M*(b-a)*(maxFunc-minFunc)/N;
193- double sum = 0 ;
194- for (int i = 0 ; i < y_integral.size (); i++)
195- sum += y_integral[i];
209+ double integral = (M * a * b) / N;
196210 this ->label_integral ->Text = " Èíòåãðàë: " + integral.ToString ();
197- this ->label_checkIntegral ->Text = " Ïðîâåðêà: " + method_Sympsona (0 ,5 ,N,numVar).ToString ();
198-
211+ this ->label_checkIntegral ->Text = " Ñèìïñîí: " + method_Sympsona (0.0 , a, N, numVar, false );// method_LeftRectangle(0.0, a, N).ToString();
199212}
200213
201214System::Void MethodMonteKarlo::InteractionForm::ToolStripMenuItem_openForm2_Click (System::Object^ sender, System::EventArgs^ e)
@@ -210,4 +223,11 @@ for (int i = 0; i < 1000+; i++)
210223{
211224 this->table_values->Columns->Add("col" + i, "colu" + i);
212225 this->table_values->Columns[i]->FillWeight = 70;
213- }*/
226+ }*/
227+
228+ /* //Ìîíòå-Êàðëî èíòåãðà~ñóììà
229+ double check = 0;
230+ totalSum = 0;
231+ for (int i = 0; i < x_integral.size(); i++)
232+ totalSum += functionIntegral(x_integral[i], numVar);
233+ check = (5.0 / (double)x_integral.size()) * totalSum;*/
0 commit comments