f

#### Help! Strange behavior when using Matlab calling Maple's "Binomial" function?

```HI all,

I found the following strange thing regarding "maple" and "sym" function:
"k" is an integer:
"a" is an array of symbolic numbers:

Code (1):
---------------

for m=0:k
s(m+1)=maple('binomial', sym(k), sym(m));
end
res=s*((-1).^[0:k].*a(1:k+1))';

Result:

K>> vpa(res, 10)

ans =

-595.0

Code (2):
---------------
for m=0:k
s(m+1)=sym(['binomial(',num2str(k, 200),',',num2str(m, 200),')']);
end
r=s*((-1).^[0:k].*a(1:k+1))';

Result:

K>> vpa(r, 10)

ans =

-.61e3

------------------------------------

This finding horrified me! It took me 2 hours to idenify that the problem
lies in these two lines. Fortunately I kept the second version which was
known to be correct by comparing with theoretical results. That's to say,
the second version was an earlier version, and it is known to be correct.
And then I changed to the 1st version. Then I got wrong answer. The error
got cumulated and the reuslt is way off from the 2nd version(the 2nd is
theoretically correct). But why is the 1st version wrong?

Note that "k" and "m" are integers and so they ought to have no rouding
errors...

I want to make the 1st version correct, because as I've described in the
previous posts,

when it comes to floating numbers, let's say "k" and "m" are 2.33333333 and
3.16666666.

Then "num2str" does not work well.

Also, if I've already defined a variable "K" and "M" to be symbolic object,
then using

maple('binomial', K, M);

are very natural choice.

Now the problem is: it seems that this "maple" function is not reliable?
What happened to the 1st version?

-------------

Please, shed me some lights on this! I am desperate!

```
 0
housing2006 (283)
12/30/2006 10:19:58 AM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader.

1 Replies
1402 Views

Similar Articles

[PageSpeed] 21

```Here is another part of my program in which I definitely have to use
"maple('binomial')" function:

c=sym(5);
delta=sym(0.3);

R=c/delta;
for k=0:n;
p(k+1)=maple('binomial', R+k-1, k);
end;

-----------------------

Note there I could not use

p(k+1)=sym(['binomial(',num2str(R+k-1, 200),',',num2str(k, 200),')']);

at all.

------------------------

So I really hope to find out why is the "maple('binomial')" approach wrong?

Any thoughts? Thanks a lot!

```
 0
housing2006 (283)
12/30/2006 10:24:50 AM