# Matrix Formula

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 12-08-2004
Junior89
Matrix Formula
I need to have a C++ program run through this equation:

[Matrix M]= 1/(AD-BC) * [D -B -C A]

and then...

Multiply this answer to another matrix which in the end will end up as all Whole numbers (ints). If anyone has a basic knowledge of Regular and Inverse Matrices and can figure out how to solve this problem i would really appreciate it. Thanks!
• 12-08-2004
axon
I'm on it....I should be done at about 4am central time....so, in the mean time, don't do anything and it'll be ready for you. Would you like me to email it, or should I post it here?
• 12-08-2004
xErath
I've made a fully functional Matrix class, to use with OpenGL... but I think you should 1st try to do something youself. Later I can give you some bits...
Code:

```#define MATRIX_IDENTITY ((const float**)0x00000004) #define MATRIX_EMPTY        ((const float**)0x00000002) class Matrix{ private:         float* matrix;         int h,w;//height, width         void buildBuf();         friend bool check1(const Matrix& m);//auxiliaries for invert         friend bool check2(Matrix& m);         Matrix* synched;         bool dosync; public:         Matrix(int h=1,int w=1,const float** = MATRIX_EMPTY);         Matrix(int,int,const float*);         Matrix(const Matrix&);         ~Matrix();         void sync(Matrix&);//all basic operations are made both on this matrix and the one synched         bool unsync();         Matrix* getSynched();         inline int getHeight() const;         inline int getWidth() const;         float* operator[](int) const;         bool invert();         void mkIdentity();         void mkEmpty();         //basic operations         void swapRow(int,int);         void swapCol(int,int);         void addMultRow(int,int,float=1.0);         void addMultCol(int,int,float=1.0);         void multRow(int,float);         void multCol(int,float);         //boolean operators         Matrix& operator=(const Matrix&);//doesn't change synched         bool operator==(const Matrix&) const;         bool operator!=(const Matrix&) const;         //arithmetic operators, aren't aplied on synched         Matrix& operator+=(const Matrix&);         Matrix  operator+ (const Matrix&) const;         Matrix& operator-=(const Matrix&);         Matrix  operator- (const Matrix&) const;         Matrix& operator*=(const Matrix&);         Matrix  operator* (const Matrix&) const;         Matrix& operator*=(float);         Matrix  operator* (float) const;         //debuging         void print() const; }; Matrix operator*(float, const Matrix&);```
And an example of it's usage with your problem
[Matrix M]= 1/(AD-BC) * [D -B -C A]
Code:

```Matrix A(...),B(...),C(...),D(...); Matrix temp = A*D - B*C; if(!temp.invert()){     std::cerr<<"Matrix not invertible.\n"     //break; return; exit();... whatever } Matrix M = temp*(D-B-C-A);```
• 12-08-2004
PJYelton
>>I'm on it....I should be done at about 4am central time....so, in the mean time, don't do anything and it'll be ready for you. Would you like me to email it, or should I post it here?
<<

4am?? Slacker.

I'll have it done and on your doorstep by 2am, oh, and my first born child too. Watch it, hes cranky that time of night though.
• 12-09-2004
VirtualAce
4 am and 2 am!! Hah!!! I've got both of you beat. My code is already done but since I've completed it earlier than expected I require a small investment to be made. And I accept credit cards, too.

;)
• 12-10-2004
AH_Tze
To spell it out for the thread-starter:

"The purpose of these board is not for other people to do your homework for you. Try things out work on your own, homework has a purpose. If you still have trouble with a specific piece of code or concept please feel free to ask. But please do not ask people to do your entire homework for you, it simply annoys people most of the time. "

Attempt the problem. Everyone get's stuck on odd esoteric parts of C++, and you'll easily find someone to assist you, but only after you show some effort.
• 12-10-2004
Zach L.
Some things to look at:
i. Arrays. The tutorials on www.cprogramming.com will tell you about them.
ii. If you need mathematical help, I would suggest MathWorld.
iii. And if you have specific questions, feel free to ask.
• 12-11-2004
Junior89
first off let me say this to the person who thinks this is for my "Homework" i am not enrolled in a c++ class anywhere im only in high school, i learned about a crypographic method using matrices and wanted to make a computer program with it. When i got to using inverse matrices on the computer i came across a porblem it wouldn't work. I am doing this for me not some C++ class.

To the others: Thank you for your help and if you have code please post it here on the forum. Thanks very much!
• 12-11-2004
7smurfs
Quote:

Originally Posted by Junior89
first off let me say this to the person who thinks this is for my "Homework" i am not enrolled in a c++ class anywhere im only in high school, i learned about a crypographic method using matrices and wanted to make a computer program with it. When i got to using inverse matrices on the computer i came across a porblem it wouldn't work. I am doing this for me not some C++ class.

To the others: Thank you for your help and if you have code please post it here on the forum. Thanks very much!

It sounds like an Advanced Algebra homework assignment to me, so maybe thats what he thought it was. Also, you havn't shown anybody here that you have put any effort outside of posting here in attempting the problem. We're programmers not phycics. I would go with what xErath said, however.
• 12-11-2004
VirtualAce
First of all you have not specified how many rows or columns this matrix has. Second you have given us no clue about where the variables go or what they are supposed to accomplish and/or represent.

All of that information is extremely vague. What do you mean by run it through a matrix? Do you realize how many different transformations you can accomplish via matrices? Do you have any idea how many mathematical algos use matrices? Gimme a break man.

It's obvious you do not know about matrices or you would know why the inverse did not work. I would suggest either reading a book concerning matrix math and/or read some of the graphics tutorials on this site and others like it.

Not all matrices have an inverse. Not all matrices can satisfy M(M^-1)=M.
Regular matrices is a term I've never heard and I work with matrices all the time in 3D graphics. What do you mean by this?

And if you go do a search on the game programming board I posted a huge thread not too long ago about how to go about computing the inverse of a matrix and several other useful matrix functions.

Given your use of variables I'd say you are trying to solve a problem having to do with planes.

A+B+C+D=0
• 12-11-2004
Zach L.
I have a feeling I know what the encryption algorithm you are talking about is, but:
b. Please try the problem and post back with specific problems... Even is they are conceptual questions, people will be much more helpful if you have tried, and shown that you have put thought into it.

Cheers
• 12-18-2004
Junior89
Just a comment to "7Smurfs" or whatever that stupid name was, would an Advanced Algebra Class get into C++ programming? Im in an Honors Algebra 2 class, we worked on identity and inverse matrces for like one day and in the book it talked about a WWII method of cryptography that interested me, i wanted to try it. Im in 9th freeking grade cut me a break!

In any event to the others i will try to get my program posted up here shortly it works by encoding 4 letters at a time (so a 2x2 matrix). Thanks again.
• 12-18-2004
Zach L.
The algorithm I'm familiar with is the following. Say your encryption key A, is an n*n invertible matrix (and call itsinverse A')). Then, line up your letters in an m*n array, such that m*n > #(letters), and add some padding at the end. Call this message matrix M.

Then, the product M*A is a m*n: M*A = M'
Then, M'*A' = (M*A)*A' = M*(A*A') = M*1 = M

Hence, you can do your whole message. Of course, this isn't a terribly secure method of encryption, but it is a fun one to play with.

Cheers
• 12-18-2004
Kybo_Ren
Quick question: are you using the Glencoe Algebra 2 book? It's red. Just wondering.
• 12-18-2004
Junior89
Yeah i think so
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last