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.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top