Worksheet Formula Returning Sum of a Series
Hi Dana;
Your Function ImSeriesSum(Rng As Range, X) works fine and produces almost
identical results to mine.
The only difficulty is that it accepts the range of coeffs as argument,
while the other functions on the w/s require the deg of poly "m" instead and
assume the (m+1) complex coeffs are in col D starting at D11. Difficult to
remember the difference later on!
Here's my latest:
Function MyImSeriesSum2(m, x)
' e.g.; eval quartic poly: m=4, f(x) = a1 + x( a2 + x( a3 + x( a4 + x( a5))))
' eval quintic poly: m=5, f(x) = a1 + x( a2 + x( a3 + x( a4 + x( a5+
x(a6)))))
' poly deg m = 2
Dim j As Integer
Dim mySum As String
ReDim a(m + 1) As String 'poly complex coefficients
For j = 1 To m + 1 'assign poly coeffs, w/s col D, starting D11: const
term, x coeff, x^2 coeff, etc.
a(j) = Cells(11 + j - 1, 4)
Next j
mySum = ImProduct(X, a(M + 1)) 'innermost term of polynomial
For j = m+1 To 3 Step -1 'remaining terms excluding const term
mySum = IMSUM(ImProduct(x, a(j - 1)), ImProduct(x, mySum))
Next j
mySum = IMSUM(a(1), mySum) 'add const term
MyImSeriesSum2 = mySum
End Function
Regards.
"monir" wrote:
Hi Dana;
1) I'll try your Function ImSeriesSum(Rng As Range, X) first thing in the
morning (in about 4 hrs!). It's neat and looks professional!
2) For now, here's a modified working version of my earlier UDF without the
use of IMPOWER:
Function MyImSeriesSum2(m, x)
' e.g.; for a quartic poly: m=4, f(x) = a1 + x( a2 + x( a3 + x( a4 + x( a5
))))
' for a quintic poly: m=5, f(x) = a1 + x( a2 + x( a3 + x( a4 + x( a5
+ x(a6)))))
' m = 2
Dim j As Integer
Dim mySum As String
ReDim a(m + 1) As String 'poly complex coefficients
.
For j = 1 To m + 1 'assign poly coeffs, w/s col D, starting D11: const
term, x coeff, x^2 coeff, x^3 coeff, etc.
a(j) = Cells(11 + j - 1, 4)
Next j
mySum = ImProduct(x, IMSUM(a(m), ImProduct(x, a(m + 1)))) 'last term of
polynomial
For j = m To 3 Step -1 'calculate remaining terms of poly excluding const
term
mySum = IMSUM(ImProduct(x, a(j - 1)), ImProduct(x, mySum))
Next j
mySum = IMSUM(a(1), mySum) 'add constant term
MyImSeriesSum2 = mySum
End Function
3) For the same numerical example posted earlier, the above function returns:
9.99200722162641E-014
compared with the earlier results (using IMPOWER):
9.9475983006414E-014 - 3.99680288865056E-014i
4) For 8th deg poly, the results a
1.97669991486293E-009 - 3.57939988759881E-009i
compared with (using IMPOWER):
1.97679916880134E-009 - 3.57938745310094E-009i
Insignificant differences really! Agree ??
I would be glad to send you a "clean" copy of the XL w/b with Function
ZRoots2() and Sub Laguer2(). I should be able to find your work email
address.
Regards.
(XL 2003, Win XP)
"Dana DeLouis" wrote:
f(x) = a1 + a2 x + a3 x^2 + a4 x^3 + a5 x^4 ....(*)
hence:
f(x) = a1 + x(a2 + x(a3 + x(a4 + x(a5)))) ..........(**)
Can we algorithmically evaluate (**) using only IMSUM and IMPRODUCT
Hi. Yes. Exactly That is basically the idea behind the code I posted
about two up from this thread when I thought your Poly might be large.
Here's a copy...
Anyway, always an interesting subject.
I still would love to see your ZRoot code. :)
Function ImSeriesSum(Rng As Range, X)
' Rng is a single-column range on a worksheet
' holding complex values (or real's for that matter)
Dim j As Long
Dim Ans
Dim M
M = Rng.Cells.Value
Ans = M(UBound(M, 1), 1)
With WorksheetFunction
For j = UBound(M, 1) - 1 To 1 Step -1
Ans = .ImSum(M(j, 1), .ImProduct(Ans, X))
Next j
End With
ImSeriesSum = Ans
End Function
--
Dana DeLouis
<snip
|