Re: please check my homework



Michael Jørgensen wrote:
"David Marsh" <dmarsh@xxxxxxxx> wrote in message
news:sAw7f.306880$tl2.244927@xxxxxxxxxxx

This is a homework assignment for extra credit. The statistical
material has not been covered in class. Is my bidist() function
correct? It seems to work with the examples I have tried, but I
would appreciate your comments and suggestions. PLEASE don't
write any code. Error checking deliberately omitted for now and I
am aware of the potential for factorials to exceed LDBL_MAX.

David
---------------------------------------------------------------

<snip code>

Write also a test function that calculates: f(0) + f(1) + f(2) + ... +
f(n-1) + f(n). This sum should be exactly 1.0 for all valid values of n and
p.

/* test function -- when plotted, the intermediate values produce the curve of the binomial distribution */ void bidist_test(long double p, long double n, long double x) { long double fn, fx, fnx, t1, t2, t3; long double sum, xx, ival;

    sum = 0.0;
    for(xx = 0.0; xx <= n; xx++)
    {
        fn = factorial(n);
        fx = factorial(xx);
        fnx = factorial(n-xx);
        t1 = fn / (fx * fnx);
        t2 = (long double)pow(p, xx);
        t3 = (long double)pow(1.0-p, n-xx);
        ival = t1 * t2 * t3;
        sum += ival;
        printf("%Lf\n", ival);
    }
    printf("\n%Lf\n", sum);
    return;
}

sample output:
p=.5, n=12, x=5

0.000244
0.002929
0.016113
0.053710
0.120850
0.193359
0.225586
0.193359
0.120850
0.053710
0.016113
0.002929
0.000244

1.000000

David
.



Relevant Pages

  • Re: sum R
    ... david once again misunderstood. ... who said the sum is restricted to zero's? ... the sums over the reals if convergeant. ... however there is a different between defined integrals and arbitrary integrals or series. ...
    (sci.math)
  • Re: How do you say Im a Juggler in your language?
    ... Scott Seltzer wrote: ... Ego pilarius sum or Ego pilicrepus sum (both names meant "ball ... David, I'm sure that you love Jews. ...
    (rec.juggling)
  • Re: How do you say Im a Juggler in your language?
    ... Ego pilarius sum or Ego pilicrepus sum (both names meant "ball ... juggler") Ego ventilator sum. ... David, I'm sure that you love Jews. ...
    (rec.juggling)
  • Re: Well Ordering the Reals
    ... > David R Tribble said: ... > Tony Orlow wrote: ... number of terms AND the same sum, and caliming so is patently false. ...
    (sci.math)
  • Re: A Poker Problem (Heads Up)
    ... >David C. Ullrich wrote: ... >>>only allowed to raise N times. ... sum, and it's not at all clear to me that the ...
    (sci.math)