Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Compute a geomtric series with matrices

  1. Feb 25, 2006 #1
    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 in C that computes the following.

    I(indentity matrix)

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

    I tried

    sum=I;
    for(i=0;i<k;i++)
    {
    intermediary=mult(I,A);
    sum+=intermediary;
    intermediary=mult(intermediary,A)
    }


    Am I right?
    Please, What is wrong here?

    Thank you for yout help
    B
     
  2. jcsd
  3. Feb 25, 2006 #2
    //This should have been the code
    sum=I;
    intermediary = I;
    for(i=0;i<k;i++)
    {
    intermediary=mult(intermediary,A)
    sum+=intermediary;
    }

    Now what was wrong in your code?
    sum=I;
    for(i=0;i<k;i++)
    {
    intermediary=mult(I,A); <---- Look at this, intermediary is set to IxA everytime here
    sum+=intermediary;
    intermediary=mult(intermediary,A)
    }

    -- AI
     
  4. Feb 25, 2006 #3
    Yes !I see now what I have done wrong.
    thanks a lot.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Compute a geomtric series with matrices
  1. Computer vision (Replies: 1)

  2. Computer language (Replies: 4)

  3. Computational Physics (Replies: 1)

  4. Sparse matrices (Replies: 1)

Loading...