Консультация № 175299
15.12.2009, 18:55
35.00 руб.
0 5 1
Доброго времени суток уважаемые эксперты!!!
Обращаюсь к Вам со следующим:
1) Создать процедуру генерации 2 выборок - (хi, i={1,n}) и yi, i={1,n} с равномерным, нормальным, и показательным законом распределения в диапазоне [0,1]. Объём выборки n задаёт пользователь программного обеспечения. Значения выборок сохранить в динамическом массиве. Осуществить вывод значений хi и yi на экран монитора.
2) Выборке yi задать приращение z. z=[0,01;0,3]. Вводит пользователь. Значения выборки сохранить в динамическом массиве. Осуществить вывод значений.
3) Построить оценку функции распределения вероятностей. Осуществить вывод графиков функции распределения.
ВСЕ ЭТИ ПУНКТЫ Я СДЕЛАЛ, ТЕПЕРЬ САМ ВОПРОС
Нужно найти максимальное расстояние полученными графиками между графиками!!! Проект создавался в Microsoft Visual Studio 2008 в приложении Windows Forms.



Приложение:
#pragma once
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;

namespace Laba3 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Сводка для Form1
///
/// Внимание! При изменении имени этого класса необходимо также изменить
/// свойство имени файла ресурсов ("Resource File Name") для средства компиляции управляемого ресурса,
/// связанного со всеми файлами с расширением .resx, от которых зависит данный класс. В противном случае,
/// конструкторы не смогут правильно работать с локализованными
/// ресурсами, сопоставленными данной форме.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}

protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::ComboBox^ comboBox2;
private: System::Windows::Forms::ListBox^ listBox1;
private: System::Windows::Forms::ListBox^ listBox2;
private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
private: System::Windows::Forms::NumericUpDown^ numericUpDown2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::NumericUpDown^ numericUpDown3;
private: System::Windows::Forms::ListBox^ listBox3;
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
private: System::Windows::Forms::NumericUpDown^ numericUpDown4;




private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea3 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Legend^ legend3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
System::Windows::Forms::DataVisualization::Charting::Series^ series5 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
System::Windows::Forms::DataVisualization::Charting::Series^ series6 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
this->button1 = (gcnew System::Windows::Forms::Button());
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
this->listBox1 = (gcnew System::Windows::Forms::ListBox());
this->listBox2 = (gcnew System::Windows::Forms::ListBox());
this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->numericUpDown3 = (gcnew System::Windows::Forms::NumericUpDown());
this->listBox3 = (gcnew System::Windows::Forms::ListBox());
this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
this->numericUpDown4 = (gcnew System::Windows::Forms::NumericUpDown());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown3))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->chart1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown4))->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(13, 384);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Рассчитать";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// comboBox1
//
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"Равномерный", L"Нормальный", L"Показательный"});
this->comboBox1->Location = System::Drawing::Point(86, 36);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(121, 21);
this->comboBox1->TabIndex = 1;
//
// comboBox2
//
this->comboBox2->FormattingEnabled = true;
this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"Равномерный", L"Нормальный", L"Показательный"});
this->comboBox2->Location = System::Drawing::Point(86, 74);
this->comboBox2->Name = L"comboBox2";
this->comboBox2->Size = System::Drawing::Size(121, 21);
this->comboBox2->TabIndex = 2;
//
// listBox1
//
this->listBox1->FormattingEnabled = true;
this->listBox1->Location = System::Drawing::Point(397, 34);
this->listBox1->Name = L"listBox1";
this->listBox1->Size = System::Drawing::Size(120, 95);
this->listBox1->TabIndex = 3;
//
// listBox2
//
this->listBox2->FormattingEnabled = true;
this->listBox2->Location = System::Drawing::Point(537, 34);
this->listBox2->Name = L"listBox2";
this->listBox2->Size = System::Drawing::Size(120, 95);
this->listBox2->TabIndex = 4;
//
// numericUpDown1
//
this->numericUpDown1->Location = System::Drawing::Point(244, 37);
this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1316134912, 2328, 0, 0});
this->numericUpDown1->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
this->numericUpDown1->Name = L"numericUpDown1";
this->numericUpDown1->Size = System::Drawing::Size(137, 20);
this->numericUpDown1->TabIndex = 5;
this->numericUpDown1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
//
// numericUpDown2
//
this->numericUpDown2->Location = System::Drawing::Point(244, 75);
this->numericUpDown2->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {-1486618624, 232830643, 0, 0});
this->numericUpDown2->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
this->numericUpDown2->Name = L"numericUpDown2";
this->numericUpDown2->Size = System::Drawing::Size(137, 20);
this->numericUpDown2->TabIndex = 6;
this->numericUpDown2->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(13, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(171, 13);
this->label1->TabIndex = 7;
this->label1->Text = L"Выберите закон распределения";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(454, 9);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(146, 13);
this->label2->TabIndex = 8;
this->label2->Text = L"Сгенерированные выборки";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(241, 9);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(140, 13);
this->label3->TabIndex = 9;
this->label3->Text = L"Выберите объем выборки";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(13, 36);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(67, 26);
this->label4->TabIndex = 10;
this->label4->Text = L"Для первой\r\nвыборки";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(14, 74);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(66, 26);
this->label5->TabIndex = 11;
this->label5->Text = L"Для второй\r\nвыборки";
//
// numericUpDown3
//
this->numericUpDown3->DecimalPlaces = 2;
this->numericUpDown3->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 131072});
this->numericUpDown3->Location = System::Drawing::Point(87, 129);
this->numericUpDown3->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {3, 0, 0, 65536});
this->numericUpDown3->Name = L"numericUpDown3";
this->numericUpDown3->Size = System::Drawing::Size(120, 20);
this->numericUpDown3->TabIndex = 12;
//
// listBox3
//
this->listBox3->FormattingEnabled = true;
this->listBox3->Location = System::Drawing::Point(16, 174);
this->listBox3->Name = L"listBox3";
this->listBox3->Size = System::Drawing::Size(120, 95);
this->listBox3->TabIndex = 13;
//
// chart1
//
chartArea3->Name = L"ChartArea1";
this->chart1->ChartAreas->Add(chartArea3);
legend3->Name = L"Legend1";
this->chart1->Legends->Add(legend3);
this->chart1->Location = System::Drawing::Point(217, 135);
this->chart1->Name = L"chart1";
series5->ChartArea = L"ChartArea1";
series5->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
series5->Legend = L"Legend1";
series5->Name = L"График";
series6->ChartArea = L"ChartArea1";
series6->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Spline;
series6->Legend = L"Legend1";
series6->Name = L"График2";
this->chart1->Series->Add(series5);
this->chart1->Series->Add(series6);
this->chart1->Size = System::Drawing::Size(440, 158);
this->chart1->TabIndex = 14;
this->chart1->Text = L"chart1";
//
// numericUpDown4
//
this->numericUpDown4->DecimalPlaces = 2;
this->numericUpDown4->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 131072});
this->numericUpDown4->Location = System::Drawing::Point(15, 313);
this->numericUpDown4->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
this->numericUpDown4->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 131072});
this->numericUpDown4->Name = L"numericUpDown4";
this->numericUpDown4->Size = System::Drawing::Size(120, 20);
this->numericUpDown4->TabIndex = 15;
this->numericUpDown4->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 131072});
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(684, 470);
this->Controls->Add(this->numericUpDown4);
this->Controls->Add(this->chart1);
this->Controls->Add(this->listBox3);
this->Controls->Add(this->numericUpDown3);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->numericUpDown2);
this->Controls->Add(this->numericUpDown1);
this->Controls->Add(this->listBox2);
this->Controls->Add(this->listBox1);
this->Controls->Add(this->comboBox2);
this->Controls->Add(this->comboBox1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Лабораторная Работа №3";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown3))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->chart1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown4))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int i,n,j,h;
double *w,*q,t,z,m,r,u;
n=Convert::ToInt32(numericUpDown1->Text);
h=Convert::ToInt32(numericUpDown2->Text);
z=Convert::ToDouble(numericUpDown3->Text);
w=new double[n];
q=new double[h];
listBox1->Items->Clear();
listBox2->Items->Clear();
listBox3->Items->Clear();
chart1->Series["График"]->Points->Clear();
chart1->Series["График2"]->Points->Clear();

//=========================Генерация ряда чисел 1==================
if (comboBox1->SelectedIndex==0)
{
for (i=0;i<n;i++)
{
w[i]=(rand()%101)/100.;
listBox1->Items->Add(w[i]);

}
}
if (comboBox1->SelectedIndex==1)
{

for (i=0;i<n;i++)
{ t=0;
for (j=0;j<5;j++)
{
t+=(rand()%101)/100.;
}
w[i]=1/5.*t;
listBox1->Items->Add(w[i]);
}
}
if (comboBox1->SelectedIndex==2)
{
for (i=0;i<n;i++)
{
w[i]=pow((rand()%101)/100.,1/4.);
listBox1->Items->Add(w[i]);
}
}
//=========================Генерация ряда чисел 2==================
if (comboBox2->SelectedIndex==0)
{
for (i=0;i<h;i++)
{
q[i]=(rand()%101)/100.;
m=q[i];
listBox2->Items->Add(q[i]);
listBox3->Items->Add(m+z);
}
}
if (comboBox2->SelectedIndex==1)
{

for (i=0;i<h;i++)
{ t=0;
for (j=0;j<5;j++)
{
t+=(rand()%101)/100.;
}
q[i]=1/5.*t;
r=q[i];
listBox2->Items->Add(q[i]);
listBox3->Items->Add(r+z);
}
}
if (comboBox2->SelectedIndex==2)
{
for (i=0;i<h;i++)
{
q[i]=pow((rand()%101)/100.,1/4.);
u=q[i];
listBox2->Items->Add(q[i]);
listBox3->Items->Add(u+z);
}
}
//=========================Графики=================================
double x,P,p,xx,PP,pp;
int g,gg;
x=Convert::ToDouble(numericUpDown4->Text);
xx=Convert::ToDouble(numericUpDown4->Text);
for (p=0;p<1;p+=x)
{
t=0;
for (i=0;i<n;i++)
{
if (p-w[i]>=0)
g=1;
else
g=0;
t+=g;
}
P=(double)t/n;
chart1->Series["График"]->Points->AddXY(p,P);
}
for (pp=0;pp<1;pp+=xx)
{
t=0;
for (i=0;i<h;i++)
{
if (pp-(w[i]+z)>=0)
gg=1;
else
gg=0;
t+=gg;
}
PP=(double)t/h;
chart1->Series["График2"]->Points->AddXY(pp,PP);
}


}
};
}

Обсуждение

Неизвестный
15.12.2009, 19:02
общий
Все первые три пункта выполнены верно! Нужно лишь найти максимальное расстояние между графиками и желательно выделить его в chart'е
давно
Профессор
230118
3054
20.12.2009, 13:27
общий
Баженов Павел Андреевич:
Насколько я понимаю, рисование графиков находится в конце. Вы считаете значения в двух различных циклах. Но если присмотреться, координаты x в обоих случаях те же, и поэтому эти циклы можно объединить. При этом считайте расстояние между графиками как |p-pp|. Ничего сложного.
давно
Старший Модератор
17042
808
24.12.2009, 19:54
общий
Ashotn:
Может, подадите Ваш комментарий как ответ?
Об авторе:
We have but faith: we cannot know;
For knowledge is of things we see;
And yet we trust it comes from thee,
A beam in darkness: let it grow.
-----
https://www.linkedin.com/in/andreynkuznetsov
https://www.researchgate.net/profile/Andrey_Kuznetsov11
http://www.researcherid.com/rid/K-8824-2014
Неизвестный
24.12.2009, 21:33
общий
Господа, в принципе я уже с подсказки осуществил это! Спасибо!
давно
Профессор
230118
3054
24.12.2009, 22:17
общий
это ответ
Здравствуйте, Баженов Павел Андреевич.

Вот Ваш код рисования графиков.
Код:
double x,P,p,xx,PP,pp;
int g,gg;
x=Convert::ToDouble(numericUpDown4->Text);
xx=Convert::ToDouble(numericUpDown4->Text);
for (p=0;p<1;p+=x)
{
t=0;
for (i=0;i<n;i++)
{
if (p-w[i]>=0)
g=1;
else
g=0;
t+=g;
}
P=(double)t/n;
chart1->Series["График"]->Points->AddXY(p,P);
}
for (pp=0;pp<1;pp+=xx)
{
t=0;
for (i=0;i<h;i++)
{
if (pp-(w[i]+z)>=0)
gg=1;
else
gg=0;
t+=gg;
}
PP=(double)t/h;
chart1->Series["График2"]->Points->AddXY(pp,PP);
}

В первом цикле рисуется график 1, во втором график 2. Так как переменные циклов принимают те же значения, их можно объединить.

for (p=0;p<1;p+=x)
{
....
P=(double)t/n;
chart1->Series["График"]->Points->AddXY(p,P);
....
PP=(double)t/h;
chart1->Series["График2"]->Points->AddXY(p,PP);
d=abs(P-PP);
}

d - это есть расстояние между графиками в данной точке. По известному алгоритму находим максимальное среди всех точек.
5
Спасибо за ответ!!!
Форма ответа