Compute a geomtric series with matrices

1. Feb 25, 2006

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

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?

Thank you for yout help
B

2. Feb 25, 2006

TenaliRaman

//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

3. Feb 25, 2006