How to program a series sum function

J

Joao

Hi there !

I want to create a math function that can emulate a series sum of any
kind, for instance:

series sum for i=1 to n (1/(i+2)^+B2) or whatever.

For what I have seen in the help menu, there is a seriesum function
but is a standard sin/cos series function and I couldn't find anything
else.

Can anyone help me doing this ?

Thanks/brgds
jj
 
B

Bernie Deitrick

Joao,

You can use a User-Defined-Function, see sample code below. Of course, you
will need to make it a little smarter if you want to use cell references for
parameters. Used like

=SeriesSum(B2,100)

where B2 has the string, for example,

1/(i+2)^2

This would return the sum for 1 = 1 to 100 of 1/(i+2)^2

HTH,
Bernie
MS Excel MVP

Function SeriesSum(Arg As String, N As Integer) As Double
Dim i As Integer
For i = 1 To N
SeriesSum = SeriesSum + Evaluate(Replace(Arg, "i", i))
Next i
End Function
 
J

Joao

Thanks Bernie - great help.
Brgds
Joao

Bernie Deitrick said:
Joao,

You can use a User-Defined-Function, see sample code below. Of course, you
will need to make it a little smarter if you want to use cell references for
parameters. Used like

=SeriesSum(B2,100)

where B2 has the string, for example,

1/(i+2)^2

This would return the sum for 1 = 1 to 100 of 1/(i+2)^2

HTH,
Bernie
MS Excel MVP

Function SeriesSum(Arg As String, N As Integer) As Double
Dim i As Integer
For i = 1 To N
SeriesSum = SeriesSum + Evaluate(Replace(Arg, "i", i))
Next i
End Function
 
Top