Thread: Matrix Formula

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Exclamation 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!

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    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?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    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...
    Here's the header
    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);
    Last edited by xErath; 12-08-2004 at 10:03 PM.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    >>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.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.


  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    82
    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.

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    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!

  9. #9
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    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.
    To code is divine

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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

  11. #11
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I have a feeling I know what the encryption algorithm you are talking about is, but:
    a. Please provide more details.
    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
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  12. #12
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    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.

  13. #13
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  14. #14
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Quick question: are you using the Glencoe Algebra 2 book? It's red. Just wondering.

  15. #15
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Yeah i think so

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM