Автор: Genadyruk
Дата сообщения: 26.03.2013 21:28
люди скажите пожалуйста где у меня тут ошибка? спасибо
// U(0,t) = t, U(l,t) = t*t - граничные условия
// U(x,0) = x - начальные условия
#include <cmath>
#include <math.h>
#include <iostream>
using namespace std;
double function(double **array, double a, double b, double c, double d, int e, int f);
int main()
{
double lambda = 0.5, h, tau;
double a,b,c = 0.,d,k;
// a & b - left and right border for x
// c & d - left and right border for time
// k - cofficient of termal conductivity
// nx - number for x
// nt - number for time
// lambda - determines of stability(lambda <= 0.5)
int nx, nt;
cout << "enter left border for x"<< endl;
cin >> a;
cout << "enter right border for x"<<endl;
cin >> b;
if (a > b)
{
cout << "ERROR! Left border > right border";
return 0;
}
cout << "enter right border for time" << endl;
cin >> d;
cout << "enter cofficient of termal conductivity" << endl;
cin >> k;
if ( k < 0. ) { cout << "ERROR! Coffiecient of termal conductivity is not may be < 0!"; return 0;}
cout << "enter number n(note: this number is determines the size grid for x)" << endl;
cin >> nx;
h = (b - a)/nx;
tau = lambda*h*h/k;
nt = ((d - c)/tau) + 1;
double **u = new double*[nt];
for (int i = 0; i<nt; i++)
{
u[i] = new double[nx];
}
function (u, a, h, tau, lambda, nx, nt);
for (int i = 0; i<nt; i++)
{
delete [] u[i];
}
delete u;
return 0;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
double function (double **u, double a, double h, double tau, double lambda, int nx, int nt)
{
double x, x0 = a, t0 = 0., t;
int i, j, k = 0;
x = x0 + h;
j = 0;
for (i = 0; i<nx; i ++)
{
u[j][i] = x;
x = x + h;
}
t = t0 + tau;
i = 0;
for (j = 1; j<nt; j++)
{
u[j][i] = t;
t = t + tau;
}
t = t0;
i = nx;
for (j = 1; j<nt; j++)
{
u[j][i] = t*t;
t = t + tau;
}
for ( int j = 0; j < nt - 1; j++)
{
for ( int i = 1; i<nx-1; i++)
{
u[j+1][i] = lambda*u[j][i + 1] + (1. - 2.*lambda)*u[j][i] + lambda*u[j][i - 1];
cout << u[j][i]<<endl;
k = k + 1;
if ( k == 100 )
{
return 0;
}
}
}
}