A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Worksheet Formula Returning Sum of a Series



 
 
Thread Tools Display Modes
  #21  
Old July 4th, 2008, 11:33 PM posted to microsoft.public.excel.worksheet.functions
monir
external usenet poster
 
Posts: 81
Default Worksheet Formula Returning Sum of a Series

Hi Dana;

1) Your function ImSeriesSum(Rng As Range, X) works perfectly.
The following function is a bit simpler, more adaptable to the situation at
hand, has been successfully tested, and works as well:

Function MyImSeriesSum (m, x)
' the vba ImSeriesSum() is not available in XL 2003.
' MyImSeriesSum (m, x) evaluates poly of deg "m" with complex or real
coefficients, at complex or real value x.
' had the vba ImSeriesSum function been available, one would've entered it
directly into the cell on the w/s:
' =ImSeriesSum($I$11,0,1,$D$11:INDIRECT($D$32))
' x value is in cell $I$11;
' poly coeffs in col D starting at cell $D$11 with the const term
' $D$32 has the address of the last coeff. of the poly
' In cell D32::=ADDRESS(ROW(D11)+$B$8,4,3)
' the poly deg m is specified in cell $B$8

Dim j As Integer
Dim mySum As String
ReDim a(m + 1) As String 'poly complex coefficients
mySum = 0
For j = 1 To m + 1
a(j) = Cells(11 + j - 1, 4)
mySum = IMSUM(mySum, IMPRODUCT(a(j), IMPOWER(x, j - 1)))
Next j
MyImSeriesSum = mySum
End Function

2) For m=3, values of a(k), k=1, m+1
.......a(1) in cell D11:: -1.899+1.4998i
.........a(2) in cell D12:: 2.50-11.098i
.........a(3) in cell D13:: 3.699+5.50i
..a(m+1) in cell D14:: -3.121+2.0i
value of X in cell $I$11:: -1.41509650979734+1.56059079558358i
Exact Sum value is 0.0

3) Returned result from MyImSeriesSum() is:
9.9475983006414E-014 - 3.99680288865056E-014i
which is close enough to 0.0. Agree ??

4) The remaining/resulting difficulty, or rather inconvenience, is that all
the formulas on the w/s have now become volatile when opening the w/b, and
I've to use CTRL+ALT+F9 to restore the values to the formula and referenced
cells.
That's despite the fact that I DO NOT use Volatile Functions, or Events, or
volatile option in the w/b.
I've recently posted some details under the thread: "Formula Result =
Volatile ??".

Once again, thank you kindly for your tremendous help, time, and patience in
resolving the issue. I've learned a lot in the process, and there is much to
learn!
(XL 2003, Win XP)

"Dana DeLouis" wrote:

Are you sure there's a vba function IMSERIESSUM,


Hi. No, it's a custom function that you can add to your module.
It's just something I passed along in case you wanted to use it.
It solves the following equation, where the variables could be complex.

' a + b*x + c*x^2 + d*x^3 ...etc

When working with such polynomials, it can sometimes be more numerically
stable to re-write the equation as the following.
However, for this particular problem, it didn't help us out much.
You would place the function on a regular module sheet.
Then, on a worksheet, you could use it like this:

=ImSeriesSum(A1:A4,C1)

If you send me your email address, I'll be glad to send you the workbook
if you think it would help.

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

--
HTH :)
Dana DeLouis


"monir" wrote in message
...
I'm sorry Dana. I've just posted a reply to what I thought your latest,

not
realizing that you had kindly posted two more. My apologies!

Are you sure there's a vba function IMSERIESSUM, which I asked you about
earlier today ??
Please allow me some time to re-check since I'm sure it's not available

in
XL 2003, but I could be wrong!

Kind regards.
(XL 2003, Win XP)



"Dana DeLouis" wrote:

Retuned Sum value in cell I34::should be 0.0 (or extremely small,
1.E-12

Hi. Let me change this a little.
If your input data was exact, then another program shows both the real

&
imaginary numbers to be very small (not zero, but ~*10^-14)
Usually, in these types of programs, we try to avoid using "Power"
functions where possible, and I think that's where the problem was.
Hence, let me rewrite it as this:

Now I get:
9.9475983006414E-14-5.99520433297585E-14i
which I think is a little bit closer.

Function ImSeriesSum(Rng As Range, X)
Dim Cell As Range
Dim p As Long
Dim k
Dim Ans

k = 1#
With WorksheetFunction
For Each Cell In Rng.Cells
Ans = .ImSum(Ans, .ImProduct(Cell, k))
k = .ImProduct(k, X)
p = p + 1
Next Cell
End With
ImSeriesSum = Ans
End Function

--
Dana DeLouis


"Dana DeLouis" wrote in message
news (m+1) values of a(k) in col B starting (always) cell D11
.......a(1) in cell D11:: -1.899+1.4998i
.......a(2) in cell D12:: 2.50-11.098i
.......a(3) in cell D13:: 3.699+5.50i
..a(m+1) in cell B14:: -3.121+2.0i
(address of last cell in col D is in cell D32 (D14 for this

example),
in
D32::=ADDRESS(ROW(D11)+$B$8,2,3)
value of X in cell $I$11:: -1.41509650979734+1.56059079558358i
Retuned Sum value in cell I34::should be 0.0 (or extremely small,
1.E-12 or
so)

Hi. Don't know if you would want this, but here's a vba function to

do
what you want.
One advantage is that you do not need helper cells on your worksheet.
I have excel 2007, so the engineering functions are built in.
You may have to set a vba library reference to the atp functions.
In this version, the Real part went to 0, and the imaginary part was
very small (-3.99680288865056E-14i)
You can run "SetUp" below to set up your test data.


Function ImSeriesSum(Rng As Range, X)
'// = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'// For Complex Numbers in Excel, solves SumProduct
'// (ie Dot Product of the two vectors)
'// {a,b,c,d} . {1, x^1, x^2, x^3} = a + b x + c x^2 + d x^3
'// = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Dim Cell As Range
Dim p As Long
Dim Ans

With WorksheetFunction
For Each Cell In Rng.Cells
Ans = .ImSum(Ans, .ImProduct(Cell, .ImPower(X, p)))
p = p + 1
Next Cell
End With

ImSeriesSum = Ans
End Function


Sub SetUp()
[A1] = "=COMPLEX(-1.899,1.4998)"
[A2] = "=COMPLEX(2.5,-11.098)"
[A3] = "=COMPLEX(3.699,5.5)"
[A4] = "=COMPLEX(-3.121,2)"

' C1 holds your 'X value
[C1] = "=COMPLEX(-1.41509650979734,1.56059079558358)"

[C3].Formula = "=imSERIESSUM(A1:A4,C1)"
End Sub

Returned:
-3.99680288865056E-14i

--
HTH :)
Dana DeLouis

snip


  #22  
Old July 5th, 2008, 01:13 AM posted to microsoft.public.excel.worksheet.functions
Dana DeLouis
external usenet poster
 
Posts: 468
Default Worksheet Formula Returning Sum of a Series

Hi. Glad you got it working. :)


9.9475983006414E-014 - 3.99680288865056E-014i
which is close enough to 0.0. Agree ??


One can't round the Complex String, but it is possible to round the individual parts.
If you want, here's one idea.
Seems like I found a bug in Excel 2007 vba's Complex function concerning if both inputs are zero as written below.
A quick workaround was to add 0. You can probably remove the "+0" in your version.

Sub IfYouWant()
Dim s
s = "9.9475983006414E-014 - 3.99680288865056E-014i"
With WorksheetFunction
s = .Complex( _
Round(.ImReal(s), 12) + 0, _
Round(.Imaginary(s), 12) + 0 _
)
End With
Debug.Print s
End Sub

Returns:
0


mySum = IMSUM(mySum, IMPRODUCT(a(j), IMPOWER(x, j - 1)))


Using the version with ImPower is just fine, and I'm glad it works.
Not sure, but you may find this interesting.
You had an unknown number of input data.
When Polynomials get large, one can begin to lose digits.
That's why I suggested the 3rd version.

Here's a very simple demo to show why some like to re-write polynomials in vba by factoring out the 'x term.
This isn't exactly like the programming loop, but it's close enough.
Notice that x^10 exceeds Excel's 15 digit accuracy.
In vba, the last 4 digits end in 7928, and on a worksheet they end in 7920.
By factoring in a loop, we can get the last 4 digits to return correctly at 7922.
Anyway, that's the general idea.

Sub Demo()
Dim x
x = 41
Debug.Print x ^ 10
' A little loss
Debug.Print 121 * x ^ 9 - 3 * x ^ 10
'exact answer
Debug.Print (121 - 3 * x) * x ^ 9
End Sub

1.34226593101524E+16
-654763868787928
-654763868787922

--
Good luck. :)
Dana DeLouis

snip
  #23  
Old July 5th, 2008, 02:51 AM posted to microsoft.public.excel.worksheet.functions
monir
external usenet poster
 
Posts: 81
Default Worksheet Formula Returning Sum of a Series

Hi Dana;

1) Rounding complex numbers in Excel:
With my Function MyImSeriesSum() entered in cell $I$38 which returns the
value:
9.9475983006414E-014-3.99680288865056E-014i
I have in the next cell $K$38:
=COMPLEX(ROUND(IMREAL($I$38),8),ROUND(IMAGINARY($I $38),8))
which returns 0.
The above w/s Round formula is exactly as you suggested in your Sub
IfYouWant(), but without "+0" as you also correctly predicted.

2) Your observation regarding roundoff and accumulated roundoff errors for
high-power polynomials is well taken.
Perhaps we should avoid calculating "powers of x" for polynomials.
Suppose we need to evaluate a quartic polynomial at x.
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 (or SUM
and Product for real numbers) ??
The answer is a qualified: "Yes we can!" (Sorry, I've been listing to the
news too much!)

3) I'll try to adjust the main loop based on (**) above and get rid of
IMPOWER altogether, and let you know if successful:

Function MyImSeriesSum (m, x)
'..........some code
mySum = 0
For j = 1 To m + 1
a(j) = Cells(11 + j - 1, 4)
mySum = IMSUM(mySum, IMPRODUCT(a(j), IMPOWER(x, j - 1)))
Next j
MyImSeriesSum = mySum
End Function

Kind regards.
(XL 2003, Win XP)

"Dana DeLouis" wrote:

Hi. Glad you got it working. :)

9.9475983006414E-014 - 3.99680288865056E-014i
which is close enough to 0.0. Agree ??


One can't round the Complex String, but it is possible to round the
individual parts.
If you want, here's one idea.
Seems like I found a bug in Excel 2007 vba's Complex function concerning
if both inputs are zero as written below.
A quick workaround was to add 0. You can probably remove the "+0" in your
version.

Sub IfYouWant()
Dim s
s = "9.9475983006414E-014 - 3.99680288865056E-014i"
With WorksheetFunction
s = .Complex( _
Round(.ImReal(s), 12) + 0, _
Round(.Imaginary(s), 12) + 0 _
)
End With
Debug.Print s
End Sub

Returns:
0

mySum = IMSUM(mySum, IMPRODUCT(a(j), IMPOWER(x, j - 1)))


Using the version with ImPower is just fine, and I'm glad it works.
Not sure, but you may find this interesting.
You had an unknown number of input data.
When Polynomials get large, one can begin to lose digits.
That's why I suggested the 3rd version.

Here's a very simple demo to show why some like to re-write polynomials in
vba by factoring out the 'x term.
This isn't exactly like the programming loop, but it's close enough.
Notice that x^10 exceeds Excel's 15 digit accuracy.
In vba, the last 4 digits end in 7928, and on a worksheet they end in
7920.
By factoring in a loop, we can get the last 4 digits to return correctly
at 7922.
Anyway, that's the general idea.

Sub Demo()
Dim x
x = 41
Debug.Print x ^ 10
' A little loss
Debug.Print 121 * x ^ 9 - 3 * x ^ 10
'exact answer
Debug.Print (121 - 3 * x) * x ^ 9
End Sub

1.34226593101524E+16
-654763868787928
-654763868787922

--
Good luck. :)
Dana DeLouis

snip

  #24  
Old July 5th, 2008, 03:17 AM posted to microsoft.public.excel.worksheet.functions
Dana DeLouis
external usenet poster
 
Posts: 468
Default Worksheet Formula Returning Sum of a Series

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
  #25  
Old July 5th, 2008, 06:19 AM posted to microsoft.public.excel.worksheet.functions
monir
external usenet poster
 
Posts: 81
Default Worksheet Formula Returning Sum of a Series

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

  #26  
Old July 5th, 2008, 05:38 PM posted to microsoft.public.excel.worksheet.functions
monir
external usenet poster
 
Posts: 81
Default 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

  #27  
Old July 6th, 2008, 11:28 AM posted to microsoft.public.excel.worksheet.functions
Dana DeLouis
external usenet poster
 
Posts: 468
Default Worksheet Formula Returning Sum of a Series

Hi. Glad it's working for you. :)
Here's an observation on your version. Suppose we have Deg =3 (a polynomial with 4 terms)
If we step thru your code, we call ImSum 3 times, and ImProduct 5 times.
In my version, we call ImSum 3 and ImProduct only 3 times each.
Not any better, but here are just some additional ideas:

Function ImSeriesSum3(Deg, X)
'// Assume Data starts in D11
Dim j As Long
Dim M

M = [D11].Resize(Deg + 1).Value
ImSeriesSum3 = M(Deg + 1, 1)

For j = Deg To 1 Step -1
ImSeriesSum3 = ImSum(M(j, 1), ImProduct(ImSeriesSum3, X))
Next j
End Function


If at some later point, we want to be able to call this function from vba and pass a vba array, or perhaps use either a vertical or horizontal array on the worksheet,
then we would want to adjust our input data into some "standard" form (whatever that might be).
Here, we take our 2-Dimensional array and convert it to a 1-Dimensional array (The idea is to match the data from a vba array)
I know you will not use this, but thought you might find it interesting.

Function ImSeriesSum4(Deg, X)
'// Assume Data starts in D11
Dim j As Long
Dim M

M = [D11].Resize(Deg + 1).Value
M = WorksheetFunction.Transpose(M)

ImSeriesSum4 = M(Deg + 1)
For j = Deg To 1 Step -1
ImSeriesSum4 = ImSum(M(j), ImProduct(ImSeriesSum4, X))
Next j
End Function

--
HTH :)
Dana DeLouis


"monir" wrote in message ...

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:27 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.