I updated the content of the question, as I myself understood and corrected some points. And so there are the following variables:
hx (шаг по пространству)= 0.1 ht (шаг по времени) = 0.5 Nx (Количество шагов по пространству) = 10; Nt (Количество шагов по времени) = 12; wx[i] - массив содержит все шаги по пространству wt[j] - массив содержит все шаги по времени wht[j][i]-двумерный массив по которому будет строится результирующий график; And so several problems were found:
1) Found in code
for(int i = 0; i < Nx; i++) { wx[i+1] = wx[i] + hx; //массив wht[0][i] = fn(T, i * hx); //i * hx//Исправлено. } where fn is:
//Функция Хэвисайда - Начальное условие(Граничное условие) а начальное 0-1 public:static double fn(int T, double x) { if (x >= 0) return T; else if(x < 0) return 0; } I incorrectly set the initial conditions
Like wine on a chart, among the disgrace there is a common solution “wave” somewhere, but the rest is wrong there just because I incorrectly set the initial conditions in the code
2) Cycles and arrays, namely:
There is a call to a non-existent element of the array and therefore there are terrible numbers and a jump in the graph, but I cannot change the indices because there is a certain formula.
for(int j = 0;j<Nt;j++) { for(int i = 1;i<Nx-1;i++)///Исправлено с помощью ответа пользователя Denis Protopopov(и график немного изменился) { wht[j+1][i] = ((wht[j + 1][i] - wht[j][i]) / ht) + a * ((wht[j][i+1] - wht[j][i]) / hx); wht[j+1][i] = -a * (ht * (wht[j][i+1] + wht[j][i]) / hx) + (wht[j][i]); } } If I write instead of i = 0 , i = 2 or j = 2 , then the drawing of the chart will be terrible.
All code:
public:static double qx0(double x)//ось пространства { if (x<=0) return 0; else return x; } public:static double qt0(double t)//ось по времени { if (t<=0) return 0; else return t; } public:static double fn(int T,double x)//Функция Хэвисайда - Начальное условие { if (x>=0) return T; else if(x<0) return 0; } public: void drawfunc(double T) { double xmin = -5; double xmax = 10; for(double x = xmin;x<xmax;x+=0.01) { chart1->Series["Функция Хэвисайда"]->BorderWidth=3; chart1->Series["Функция Хэвисайда"]->Points->AddXY(x,fn(T,x)); } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { ///-------Переменные для работы с разностными схемами double a;//скорость переноса double hx,ht;//шаги по пространству и времени int Nx,Nt;//На сколько частей разбивае отрезок сетки int T;//Входной параметр для искомой функции(Хэвисайд) double wx[20]={0};//массив точек x double wt[20]={0};//массив точек t double wht[20][20]={0};// массив для разностной схемы(сетки) //double res[20][20]={0};//результирующий массив if(textBox1->Text!="" && textBox2->Text!="" && textBox3->Text!="" && textBox4->Text!="" && textBox5->Text!="" && textBox6->Text!="" && textBox6->Text!="") { ///-----Ввод данных----- a=Convert::ToDouble(textBox1->Text); hx=Convert::ToDouble(textBox2->Text); q=Convert::ToDouble(textBox3->Text); ht=Convert::ToDouble(textBox4->Text); Nx=Convert::ToInt32(textBox5->Text); Nt=Convert::ToInt32(textBox6->Text); T=Convert::ToInt32(textBox7->Text); //----Построение сетки,узлов for(int i = 0;i<Nx;i++) { wx[i+1]=wx[i]+hx;//массив wht[0][i]=qx0(wx[i]); } for(int j = 0;j<Nt;j++) // { wt[j+1]=wt[j]+ht; wht[j+1][0] = qt0(wt[j+1]); } ///-----------------Вычисление основых формул с разностной схемой for(int j = 0;j<Nt;j++) { for(int i = 1;i<Nx-1;i++)///Вывод формул wht[j+1][i] { wht[j+1][i]=((wht[j+1][i]-wht[j][i])/ht)+a*((wht[j][i+1]-wht[j][i])/hx); wht[j+1][i]=-a*(ht*(wht[j][i+1] + wht[j][i])/hx) + (wht[j][i])+ht*fn(wt[j],hx); } } //----Для записи в простой текстовый файл String^ fileName = "results.txt"; StreamWriter^ sw = gcnew StreamWriter(fileName); for(int j = 0;j<Nt;j++) { for(int i = 0 ;i<Nx;i++) { sw->Write("{0} ",wht[j][i]); } sw->WriteLine(); } sw->Close(); //Тестовые функции для отображения drawfunc(T);// Вызов функции для рисования ///---------------Построение графика for(int j = 0;j<Nt;j++) { for(int i = 0;i<Nx-1;i++) { chart2->Series["Series2"]->BorderWidth=3; chart2->Series["Series2"]->Points->AddXY(i,wht[j][i]); } } } else MessageBox::Show("Ошибка!Не все поля заполнены!"); } 


wht[j+1][i]overwritten by the second assignment. Secondly, the second assignment is equivalent to the relation(wht[j+1][i] - wht[j][i])/ht == -a * ( wht[j][i+1] + wht[j][i]) / hx. This, up to O (hx), is equivalent tohx * du/dt = -2au— a rigid differential equation. Let me remind you that the transfer equation isdu/dt = -a*du/dx. Before you solve with a discontinuous initial condition, make sure that you have a smooth function - the sine, will run in the right direction at the right speed. - Dmitri Chubarov