Compute a geomtric series with matrices

In summary, the conversation discusses creating a function in C to compute a geometric series with matrices, specifically the function I+A+A^2+A^3+...A^k. The correct code is shown and the mistake in the previous code is pointed out.
  • #1
brad sue
281
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
  • #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
 
  • #3
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); <---- 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.
 

FAQ: Compute a geomtric series with matrices

1. What is a geometric series?

A geometric series is a series of numbers where each term is found by multiplying the previous term by a constant. It follows the pattern: a, ar, ar^2, ar^3, ... where a is the first term and r is the common ratio.

2. How do you compute a geometric series with matrices?

To compute a geometric series with matrices, you first need to represent the series as a matrix with the first term in the first row and the common ratio in the second row. Then, you can use the formula S = a(I - r)^-1, where S is the sum of the series, a is the first term, and r is the common ratio. The resulting matrix will be the sum of all the terms in the series.

3. What is the purpose of computing a geometric series with matrices?

Computing a geometric series with matrices can be useful in various applications, such as finance, physics, and engineering. It allows for easier calculations and can help to find the sum of an infinite series.

4. Can a geometric series with matrices have a negative common ratio?

Yes, a geometric series with matrices can have a negative common ratio. This means that the terms in the series will alternate between positive and negative values.

5. Can a geometric series with matrices have a common ratio of 0?

No, a geometric series with matrices cannot have a common ratio of 0. This would result in a matrix with all 0s, making it impossible to compute the series. The common ratio must be a non-zero number for the series to have a sum.

Similar threads

Back
Top