[Dev-C++] How to get the contrary Matrix?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Justin F. <jus...@gm...> - 2004-11-25 06:34:55
|
Hi,
Sorry for my English, I'm Chinese.
I'm reading "The C++ Programming Language (Special Edition)" now, and
here is an exercise in Chap 7: 7-10-8: Write a function to invert a
two-demention array?
I tried to write some code to do it, here is a draft, for now, I don't
know how to get all arrays of a consecutive number, such as 123, we
can get 6 arrays (n!) (123,132,213,231,312,321), and how to apply this
on a two-dementions array?
And is there a great arithmetic to caculate the value of a Matrix?=20
/* Code for Exercise 7-10-8 of "The C++ Programming Language"(Special)
Here I create a function Invert(int* m, int dim) to invert a
two-dimensional array.
*/
#include <stdio.h>
using namespace std;
// Function to invert two-dimensional array=20
void invert(int* m,int dim)=20
{
=09//Step 1: Judge if the input is valid
=09=09if (m.size=3Ddim*dim) =09// N*N ranks matrix
=09=09=09=09=09
=09=09=09//Step 2: Caculate the full arrange and just their parity, then ad=
d
+ or - to each combination
=09=09=09=09int swap=3D0;
=09=09=09=09for(int n=3D1;n<=3Ddim;n++)
=09=09=09=09=09for(int i=3D1;i<=3Ddim;i++)
=09=09=09=09=09=09for(int j=3Di+1;j<=3Ddim;j++)
=09=09=09=09=09=09=09{=20
=09=09=09=09=09=09=09=09...
=09=09=09=09=09=09=09}
=09=09else
=09=09{ cerror ("Not a phalanx=EF=BC=8Cplease try again");
=09=09 exit(1);
=09=09}
=09=09=09=09
=09//Step 3: Caculate the value of the Matrix=20
=09
=09//Step 4: Caculate the value of the concomitance matrix of the original =
matrix)
=09=09int* Aplus; // the concomitance matrix
=09=09for(i=3D1;n<=3Ddim;n++)
=09=09=09for(j=3D1;i<=3Ddim;i++)
=09=09=09{
=09=09=09=09//Caculate the co-subformula of Aij=EF=BC=9B
=09=09=09=09Aplus[i][j]=3DAij;
=09=09=09}
=09
=09//Step 5: get the contrary matrix and output the result: Ainv=3DAplus/|A=
|;
=09=09for(i=3D1;i<dim;i++)
=09=09=09for(j=3D1;j<dim;j++)
=09=09=09=09Ainv[i][j]=3DAplus[i][j]/|A|;
=09=09Print_Result(...);
}
int main()
{
=09int m*;
=09cout<< "Please enter the Dimention of your array:";
=09cout<< "\nPlease input each element of your array:\n";
=09cin>>m;
=09invert(m);
}
--=20
Thanks in advance.
Z.J.
|