Thread Subject: What's the problem of the following function I defined?

Subject: What's the problem of the following function I defined?

From: HG Cho

Date: 11 Jan, 2008 11:09:02

Message: 1 of 2

function y=test(N)
Sum_tp=0;
for i=0:N-1,
     Sum_tp=Sum_tp+nchoosek(N-1,i).*((-1)^i)./(i+1)*exp
(i+1)*expint(i+1);
end
y=Sum_tp;

The function y=test(N) I defined above shows strange
results for inputs larger than about 50.

I guess there happed some resolution problem, probably in
nchoosek(n,k) function, but, I'm not sure.

I would appreciate it if you gave me clear explanation.


Subject: What's the problem of the following function I defined?

From: Anh Huy Phan

Date: 11 Jan, 2008 11:44:02

Message: 2 of 2

"HG Cho" <ddol1129@gmail.com> wrote in message
<fm7ioe$qie$1@fred.mathworks.com>...
> function y=test(N)
> Sum_tp=0;
> for i=0:N-1,
> Sum_tp=Sum_tp+nchoosek(N-1,i).*((-1)^i)./(i+1)*exp
> (i+1)*expint(i+1);
> end
> y=Sum_tp;
>
> The function y=test(N) I defined above shows strange
> results for inputs larger than about 50.
>
> I guess there happed some resolution problem, probably in
> nchoosek(n,k) function, but, I'm not sure.
>
> I would appreciate it if you gave me clear explanation.
>
>

Please refer to nchoosek function

>> help nchoosek

NCHOOSEK Binomial coefficient or all combinations.

    NCHOOSEK(N,K) where N and K are non-negative integers
returns N!/K!(N-K)!. ....
   When a coefficient is large, a warning will be produced
indicating possible inexact results. In such cases, the result
is only accurate to 15 digits for double-precision inputs, or
8 digits for single-precision inputs.

and factorial function
>>help factorial

 FACTORIAL Factorial function.
   ....


Since double precision numbers only have about 15 digits, the
answer is only accurate for N <= 21. For larger N, the answer
will have the correct order of magnitude, and is accurate for
the first 15 digits.

Anh Huy Phan
RIKEN - BSI

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com