GVA SUPPORT

³ 1326802939
Text:
	Բ =  ..

 ://  ֲ
#include <math.h>
#include <stdio.h>
#include <iostream>
using namespace std;
double ux(double x);
double ut(double t);
double* Input(double &h, double &tau, double &a, int &K, int &V);
double* Work(int &K, int &V, double &h, double &tau);
void Print(double* U, int K, int V, double h, double tau);
double ux(double x)
{    return 2*x*(1-x)+0.2;          
}       
double ut(double t)
{   return 0.2 + t;   
}
double* Input(double &h, double &tau, double &a, int &K, int &V)
{   double x1, x2, t1, t2; 
    x1 = 0;  x2 = 0.5;
    t1 = 0;  t2 = 0.5;
    h = 0.1; tau = 0.1;
    a = 0.1; 
    K = (int) ceil((x2 - x1) / h) + 1;
    V = (int) ceil((t2 - t1) / tau) + 1;
    double* U = (double*) calloc(sizeof(double), K*V); 
    return U;
}
double* Work(int &K, int &V, double &h, double &tau)
{   double a, x, t;
    double* U = Input(h, tau, a, K, V);
     for(int i = 0; i < V; i++)
        for(int j = 0; j < K; j++)                                                        
            *(U + V*i + j) = 0;                                                          
     for(int k = 0; k < K; k++)
    {
        x = k * h;                         
        *(U + V*k) = ux(x);      
    }
    
    for(int v = 0; v < V; v++)
    {   t = v*tau;                         
        *(U + v)= ut(t);               
    }
    for(int k = 1; k < K; k++)
        for(int v = 1; v < V; v++) 
            *(U + V*k + v) = (1 - a*tau/h) * *(U + V*k + v-1) + a*tau/h * *(U + V*(k-1) + v-1);
  return U; }
void Print(double* U, int K, int V, double h, double tau)
{        printf("\n %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", 218, 
         196, 196, 196, 196, 196, 196, 196, 194, 196, 196, 196, 196, 196, 196, 196, 196, 
         196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 
         196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,         
         196, 196, 196, 196, 196, 196, 196, 191);
             printf(" %c       %c%24c%24c\n", 179, 179, 'x', 179);
             printf(" %c   t   %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", 179, 195,
    196, 196, 196, 196, 196, 196, 196, 194, 196, 196, 196, 196, 196, 196, 196, 194, 
    196, 196, 196, 196, 196, 196, 196, 194, 196, 196, 196, 196, 196, 196, 196, 194, 
    196, 196, 196, 196, 196, 196, 196, 194, 196, 196, 196, 196, 196, 196, 196, 180);
      for(int i = 0; i < K; i++)
          {  if(i==0)
             {   printf(" %c       ", 179);    
                 for(int j = 0; j < V; j++)
                 printf("%c%5.1f  ", 179, j*h);
                 printf("%c\n", 179);
              printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", 195, 
                196, 196, 196, 196, 196, 196, 196, 197, 196, 196, 196, 196, 196, 196, 196, 197, 
                196, 196, 196, 196, 196, 196, 196, 197, 196, 196, 196, 196, 196, 196, 196, 197,                  
                196, 196, 196, 196, 196, 196, 196, 197, 196, 196, 196, 196, 196, 196, 196, 197, 
                196, 196, 196, 196, 196, 196, 196, 180);
              }
             printf(" %c%5.1f  ", 179, i*tau);
             for(int j = 0; j < V; j++)
                printf("%c%6.3f ", 179, *(U + V*j + i));
             printf("%c\n", 179);
           }
      printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", 192, 
         196, 196, 196, 196, 196, 196, 196, 193, 196, 196, 196, 196, 196, 196, 196, 193, 
         196, 196, 196, 196, 196, 196, 196, 193, 196, 196, 196, 196, 196, 196, 196, 193,          
         196, 196, 196, 196, 196, 196, 196, 193, 196, 196, 196, 196, 196, 196, 196, 193, 
         196, 196, 196, 196, 196, 196, 196, 217);
}
int main()
{
    double h, tau;
    int K, V;
    double* U = Work(K, V, h, tau);
    Print(U, K, V, h, tau);
    system("pause");
}


====================================