Compute a geomtric series with matrices

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    Matrices Series
Click For Summary
SUMMARY

The forum discussion focuses on computing a geometric series with matrices in C. The user initially attempts to implement the series using a loop that incorrectly resets the intermediary matrix to the product of the identity matrix and matrix A in each iteration. The correct approach involves maintaining the intermediary matrix through successive multiplications of A, allowing the series to accumulate correctly as I + A + A^2 + ... + A^k. The final solution provided clarifies the proper use of the intermediary variable.

PREREQUISITES
  • Understanding of matrix operations, specifically addition and multiplication.
  • Familiarity with C programming language syntax and functions.
  • Knowledge of geometric series and their mathematical properties.
  • Experience with iterative algorithms and loop constructs in programming.
NEXT STEPS
  • Implement matrix addition and multiplication functions in C.
  • Explore the mathematical foundations of geometric series in linear algebra.
  • Learn about matrix exponentiation techniques for efficient computation.
  • Investigate optimization strategies for matrix operations in C.
USEFUL FOR

Students and developers working with linear algebra, C programmers implementing matrix operations, and anyone interested in optimizing geometric series computations with matrices.

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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 17 ·
Replies
17
Views
5K
Replies
13
Views
4K
Replies
31
Views
4K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K