Thread: help

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    39

    help

    Hi ,
    I want to compute a geomtric series with matrices. I have the following functions:

    add (matrix1,matix2)=function to add 2 matrices.
    mult(matirx1,matrix2) =function to multiply two matrices.

    I want to create this function that computes the following.

    I(indentity matrix)

    I+A+A^2+A^3+....A^k

    I tried
    Code:
    sum=I;
    for(i=0;i<k;i++)
    {
       intermediary=mult(I,A);
        sum+=intermediary;
        intermediary=mult(intermediary,A)
       }
    but it does not work.
    Please, What is wrong here?

    Thank you for yout help

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Are we to assume that the variable I is just a typo of the variable i? In any event, since your mult() function doesn't pass any arguments by reference (with a pointer) then calling it twice in a row and assigning it over the same variable is kinda pointless isn't it?

    Code:
    sum=I;
    for(i=0;i<k;i++)
    {
       intermediary=mult(I,A);             //                             Right here <-
        sum+=intermediary;                                                             |
        intermediary=mult(intermediary,A)  // Why assign this value? It gets replaced -'
       }
    Unless you're then doing something with that intermediary value outside of the loop, which is then just poor practice leaving it in the loop for nothing.
    Last edited by SlyMaelstrom; 02-25-2006 at 03:38 PM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    39
    Quote Originally Posted by SlyMaelstrom
    Are we to assume that the variable I is just a typo of the variable i? In any event, since your mult() function doesn't pass any arguments by reference (with a pointer) then calling it twice in a row and assigning it over the same variable is kinda pointless isn't it?

    Code:
    sum=I;
    for(i=0;i<k;i++)
    {
       intermediary=mult(I,A);             //                             Right here <-
        sum+=intermediary;                                                             |
        intermediary=mult(intermediary,A)  // Why assign this value? It gets replaced -'
       }
    Unless you're then doing something with that intermediary value outside of the loop, which is then just poor practice leaving it in the loop for nothing.
    No, the I is the identity Matrix!!
    I see what you meant and I am trying to find a solution right now.

    Thank you!
    B.

Popular pages Recent additions subscribe to a feed