Excel - How to Sum infinite formula

Asked By minyeh on 22-Apr-10 11:34 PM
I am doing a transition matrix (hazard rate method) using formula
(trying to avoid using VBA under some company policy), but then, i'm
stuck when it comes to summing infinite formula.

the formula i come out with looks like this

L34:T42 is something like a {1,0,0; 0,1,0; 0,0,1} matrix (not sure
what this called, i'll just refer to matrix A) but in 9x9
L14:T22 is my Generator Matrix, also in 9x9

the formula should be:
Transition Matrix = Matrix A + T * Generator + ( T^2 / 2! ) *
Generator ^ 2 + ... +(T^infinity / infinity!) * Generator ^ infinity

Where T is # of years, i'm using T = 1 for one-year transition matrix.

for now, i'm doing up to k =4, but there is still a small gap between
what i get with the supposed-to-be actual transition matrix.

need experts' help in this summing infinite formula issue. thanks a


Dana DeLouis replied to minyeh on 23-Apr-10 12:01 AM
A Matrix with diagonal elements of 1 is called an "Identity Matrix"


I cannot quite follow.  I would suggest using Range Names to refer to
your ranges.

Looks like T is a matrix, and not a number to me.

= = = = = =
Dana DeLouis
minyeh replied to Dana DeLouis on 23-Apr-10 12:13 AM
T is not a matrix, it is a number, when u multiply a number to a
matrix, it multiply every single element in that matrix with the
number, for example, 3 * {1,2,1;,2,3,1;0,1,1} =3D {3,6,3;6,9,3;0,3,3}.


Dana DeLouis replied to minyeh on 23-Apr-10 12:46 AM
Oh.  Ok.  It looks like an interesting problem.  :>)

When you wrote...
( T^2 / 2! )

and used

MMULT(L14:T22,L14:T22) / 2

It looked to me like you were squaring the Matrix (T: L14:T22), and
dividing by 2!

As a side note:


When you raise a matrix to the 4th power, (or larger) it usually is
better to do it via vba.  I know that is not what you want though.
The reason I mention it is that if you wanted to take a matrix to the
32nd power, you have to make a very large worksheet function (32 times)
However, in vba, you can square the results in a loop just 5 times.  The
efficiency gets better as the power gets larger.

= = = = = =
HTH  :>)
Dana DeLouis
minyeh replied to Dana DeLouis on 23-Apr-10 03:09 AM

Ya, i know that limitation of using only the formula, am still
convincing IT dept to change their policy on that, but the approval
would take a while. if you can help with VBA, it will be welcome as
well : )
Dana DeLouis replied to minyeh on 24-Apr-10 07:35 PM
Hi.  You sent me a message with a 9 * 9 Input matrix, and the 9 * 9
This vba solution inputs your data from A1:I9, and outputs the data
below that beginning in A12.

The matrix converges quickly for a 1-Year.  I only looped 20 times (not
infinity) and got the same solution.

I normally would call functions in my library.  Therefore, this is a
quick and dirty way to do it.  Because the solution was in percent, I
multiplied the solution by 100.

This is just one of a few ways to show how a vba solution is, what I
think, is much easier to handle.

Sub Convergence()
Dim Y As Long
Dim J As Long
Dim Fx
Set Fx = WorksheetFunction

Y = 1 '1 Year

With ActiveWorkbook.Names
.Add "Orig", [A1].Resize(9, 9).Value
.Add "M", [A1].Resize(9, 9).Value
.Add "Ans", IdentityMatrix(9)
.Add "Ans", [Ans+M]

For J = 2 To 20
.Add "k", Y / Fx.Fact(J)    ' T/j!
.Add "M", [MMult(M, Orig)]  'Matrix to the next power
.Add "Ans", [Ans + k*M]     'Sum
Next J
.Add "Ans", [Ans*100]
[A12].Resize(9, 9) = [Ans]
End With

End Sub

Function IdentityMatrix(n)
Dim s
s = "0+(Row(#)=Column(#))"
s = Replace(s, "#", [A1].Resize(n, n).Address)
IdentityMatrix = Evaluate(s)
End Function

= = = = = = = = = =
Dana DeLouis
Dana DeLouis replied to Dana DeLouis on 25-Apr-10 04:43 PM
Hi.  Here is a slight addition that you can play with if you wish.
I just modified this portion so we can watch the convergence.
I also eliminated multiplying the answer by 100.
Just format the output as percentage to 3 decimal places does the same

For J = 2 To 20
.Add "k", Y / Fx.Fact(J)    ' T/j!
.Add "M", [MMult(M, Orig)]  'Matrix to the next power

.Add "Old", [Ans]
.Add "Ans", [Ans + k*M]     'Sum
Debug.Print J; Fx.SumXMY2([Old], [Ans])
Next J
[A12].Resize(9, 9) = [Ans]
End With
End Sub

The output is:
2  0.03359136055325
3  9.2432006386492E-04
4  1.54269946074966E-05
5  1.72307843099531E-07
6  1.35605071782519E-09
7  7.91983983820038E-12
8  3.54955567034313E-14
9  1.25992350330859E-16
10  3.62323283207642E-19
11  8.61641664106313E-22
12  1.72167126878345E-24
13  2.93590834028579E-27
14  4.50356058499773E-30
15  1.36904585529777E-32
16  4.48415508583941E-44
17  0
18  0
19  0
20  0

We can see that around 8-9 loops is all that is needed.
One can modify the code to exit once the difference gets below a certain

= = = = =
Dana DeLouis
minyeh replied to Dana DeLouis on 25-Apr-10 11:39 PM
ext power

checking the convergence is a good idea, would be very helpful in
determining how many loops required as a cut-off point. : ) Thanks a
lot really, you have been very helpful Dana.

Min Yeh