1. ## help

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 that computes the following.

I(indentity matrix)

I+A+A^2+A^3+....A^k

I tried
Code:
```sum=I;
for(i=0;i<k;i++)
{
intermediary=mult(I,A);
sum+=intermediary;
intermediary=mult(intermediary,A)
}```
but it does not work.
Please, What is wrong here?

Thank you for yout help

2. Are we to assume that the variable I is just a typo of the variable i? In any event, since your mult() function doesn't pass any arguments by reference (with a pointer) then calling it twice in a row and assigning it over the same variable is kinda pointless isn't it?

Code:
```sum=I;
for(i=0;i<k;i++)
{
intermediary=mult(I,A);             //                             Right here <-
sum+=intermediary;                                                             |
intermediary=mult(intermediary,A)  // Why assign this value? It gets replaced -'
}```
Unless you're then doing something with that intermediary value outside of the loop, which is then just poor practice leaving it in the loop for nothing.

3. Originally Posted by SlyMaelstrom
Are we to assume that the variable I is just a typo of the variable i? In any event, since your mult() function doesn't pass any arguments by reference (with a pointer) then calling it twice in a row and assigning it over the same variable is kinda pointless isn't it?

Code:
```sum=I;
for(i=0;i<k;i++)
{
intermediary=mult(I,A);             //                             Right here <-
sum+=intermediary;                                                             |
intermediary=mult(intermediary,A)  // Why assign this value? It gets replaced -'
}```
Unless you're then doing something with that intermediary value outside of the loop, which is then just poor practice leaving it in the loop for nothing.
No, the I is the identity Matrix!!
I see what you meant and I am trying to find a solution right now.

Thank you!
B.

Popular pages Recent additions