Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы по МПО / Sissy_Metr / lab2 / LAB23
.TXT
Turbo Profiler Version 2.1 Tue May 04 01:12:42 2004
Program: D:\BORLANDC\BIN\METROL~1\LAB.EXE File METROL~1\LAB.CPP
Time Counts
#include <iostream.h>
#include <conio.h>
#define rmax 5
#define cmax 5
typedef float ary[ rmax ];
typedef float arys[ cmax ];
typedef float ary2[ rmax ][ cmax ];
typedef float ary2s[ cmax ][ cmax ];
ary y;
arys g;
ary2 x;
ary2s a;
int nrow,ncol;
0.0008 999 void get_data( ary2 x, ary y, int &nrow, int &ncol)
// get the values for nrow, ncol, and arrays x,y
{
int i,j,s;
0.1117 999 nrow = 2; // this value can be chaged
0.0014 999 ncol = 2;
0.0008 999 for ( i = 0; i < nrow ; i++)
{
0.0570 1998 x[i][0] = 1;
0.0021 1998 for ( j = 1; j < ncol ; j++)
0.0017 1998 x[i][j] = i * x[i][j-1];
0.1682 1998 s = i+1;
0.0020 1998 y[i] = 2 * s;
}
0.1109 999 } // procedure get_data
0.1106 999 void write_data()
// print out the answeres
{
int i,j;
0.6031 999 clrscr();
/* cout <<"\n";
cout <<"\n X Y\n\n\n";*/
0.0009 999 for ( i = 0; i < nrow ; i++)
{
0.0576 1998 for ( j = 0; j < ncol ; j++)
0.0035 3996 continue;
/* cout <<x[i][j] <<" ";
cout <<": "<<y[i] <<"\n\n\n";*/
}
/* cout <<"\n\n A G\n\n\n";*/
Turbo Profiler Version 2.1 Tue May 04 01:12:42 2004
0.0640 999 for ( i = 0; i < ncol ; i++)
{
0.0025 1998 for ( j = 0; j < ncol ; j++)
0.0586 3996 continue;
/* cout << a[i][j]<<" ";
cout <<": " << g[i] <<"\n\n\n";*/
}
0.0008 999 }// write_data
0.0048 999 void square(ary2 x,
ary y,
ary2s a,
arys g,
int nrow,
int ncol)
//matrix multiplication routine
// a= transpose x times x
// g= y times x
{
int i,k,l;
// square
0.0009 999 for ( k = 0; k < ncol ; k++)
{
0.0019 1998 for ( l = 0; l < k ; l++)
{
0.0595 999 a[k][l] = 0;
0.0560 999 for ( i = 0; i < nrow ; i++)
{
0.0019 1998 a[k][l] = a[k][l] + x[i][l] * x[i][k];
0.2218 1998 if (k != l) a[l][k] = a[k][l];
}
} // l-loop
0.0021 1998 g[k] = 0;
0.0569 1998 for ( i = 0; i < nrow ; i++)
{
0.1187 3996 g[k] = g[k] + y[i] * x[i][k];
}
} // k-loop
0.0008 999 } // square
0.0000 1 void main()
{
0.0000 1 for (int i=1; i< 1000; i++)
{
0.0021 999 get_data(x,y,nrow,ncol);
0.0019 999 square(x,y,a,g,nrow,ncol);
0.0019 999 write_data();
}
0.0000 1 }