Compute a geomtric series with matrices

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    Matrices Series
AI Thread Summary
To compute a geometric series with matrices, the correct approach involves initializing the sum with the identity matrix and using an intermediary variable to accumulate the powers of matrix A. The initial code incorrectly re-calculated the product of the identity matrix and A in each iteration, rather than using the previously computed power. The corrected code initializes the intermediary variable to the identity matrix and updates it by multiplying with A in each loop iteration, ensuring that the sum correctly accumulates A raised to increasing powers up to k. This adjustment resolves the issue in the original implementation.
brad sue
Messages
270
Reaction score
0
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
 
Technology news on Phys.org
//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);[/Color] <---- Look at this, intermediary is set to IxA everytime here
sum+=intermediary;
intermediary=mult(intermediary,A)
}

-- AI
 
TenaliRaman said:
//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);[/Color] <---- Look at this, intermediary is set to IxA everytime here
sum+=intermediary;
intermediary=mult(intermediary,A)
}

-- AI
Yes !I see now what I have done wrong.
thanks a lot.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top