Решить матричное уравнение
2. Задан массив C(n). Сформировать матрицу A(n,n) в виде Aij=Ci*Cj и матрицу B(n,n), элементы которой вычислить по формуле Bij=Aij/max[A]. Решить матричное уравнение X(A+E)=3B-E, где E – единичная матрица.
Код:
int C[n] = { 3, 7, 6, 2, 1, 3, 5, 4, 4, 8 };
int A[n][n], E[n][n]; double B[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
A[i][j] = C[i] * C[j];
int max = A[0][0];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (A[i][j] > max)
max = A[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
B[i][j] = (double)A[i][j] / max;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
E[i][j] = rand() % 2;
int Z1[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
Z1[i][j] = 3 * B[i][j] - E[i][j];
int Z2[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
Z2[i][j] = A[i][j] + E[i][j];
double X[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
X[i][j] = (double)Z1[i][j] / Z2[i][j];
printf("C = ");
for (int i = 0; i < n; i++)
printf("%d ",C[i]);
printf("\n\n");
printf("A = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%d ",A[q][k]);
printf("\n");
}
printf("\n\n");
printf("B = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%4.2f ",B[q][k]);
printf("\n");
}
printf("\n\n");
printf("X = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%6.3f ",X[q][k]);
printf("\n");
}
printf("\n\n");
int A[n][n], E[n][n]; double B[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
A[i][j] = C[i] * C[j];
int max = A[0][0];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (A[i][j] > max)
max = A[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
B[i][j] = (double)A[i][j] / max;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
E[i][j] = rand() % 2;
int Z1[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
Z1[i][j] = 3 * B[i][j] - E[i][j];
int Z2[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
Z2[i][j] = A[i][j] + E[i][j];
double X[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
X[i][j] = (double)Z1[i][j] / Z2[i][j];
printf("C = ");
for (int i = 0; i < n; i++)
printf("%d ",C[i]);
printf("\n\n");
printf("A = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%d ",A[q][k]);
printf("\n");
}
printf("\n\n");
printf("B = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%4.2f ",B[q][k]);
printf("\n");
}
printf("\n\n");
printf("X = ");
for (int q = 0; q < n; q++)
{
for (int k = 0; k < n; k++)
printf("%6.3f ",X[q][k]);
printf("\n");
}
printf("\n\n");