Post Reply 
sum and product inside a program
03-29-2016, 09:52 PM
Post: #1
sum and product inside a program
I got strange results in one of my programs and it appears that sum() and product() don't work correctly, if called inside a program.

Example:
POLY(n,z)
BEGIN
LOCAL k;

sum(z^k/k^n, 1, 3, 1);
END;

returns +inf for POLY(2,.1).

But in CAS, from the command line, sum(0.1^k/k^2), returns .1026 . . .

Similar problem with product inside a program.
Find all posts by this user
Quote this message in a reply
03-29-2016, 11:57 PM
Post: #2
RE: sum and product inside a program
I could never get sum() to work right inside a program unless I made it a CAS program. This seems to do what you need:

#cas
POLY(n,z):=
BEGIN
LOCAL k;
sum(z^k/k^n,k,1,3,1);
END;
#end

-road
Find all posts by this user
Quote this message in a reply
03-30-2016, 12:43 AM
Post: #3
RE: sum and product inside a program
Thanks! I'll try that.
Find all posts by this user
Quote this message in a reply
05-22-2017, 11:04 PM
Post: #4
RE: sum and product inside a program
Per Cyrille:

sum is sum(expr, var, reals...)... this program is missing an EXPORT and a k in the sum to work.
EXPORT POLY(n,z)
BEGIN
LOCAL k;
sum(z^k/k^n, k, 1, 3, 1);
END;
Find all posts by this user
Quote this message in a reply
05-24-2017, 01:53 PM
Post: #5
RE: sum and product inside a program
Yes, thanks for pointing this out - - I noticed that I forgot the index variable k as soon as I started on the CAS version a while back. All is well.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)