~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libbasis/combinate.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
extern "C" {
 
3
#include <libciomr/libciomr.h>
 
4
}
 
5
 
 
6
#include <stdexcept>
 
7
#include "combinate.h"
 
8
 
 
9
StatCombData::StatCombData(int imax) :
 
10
  imax_(imax)
 
11
{
 
12
  if (imax < 1)
 
13
    throw std::runtime_error("ERROR: StatCombData::StatCombData -- argument out of range");
 
14
 
 
15
  Fact_ = new PSI_FLOAT[imax+1];
 
16
  Fact_[0] = 1.0;
 
17
  for(int i=1; i<=imax; i++)
 
18
    Fact_[i] = i*Fact_[i-1];
 
19
 
 
20
  Fact2_ = new PSI_FLOAT[imax+1];
 
21
  Fact2_[0] = 1.0;
 
22
  Fact2_[1] = 1.0;
 
23
  for(int i=2; i<=imax; i++)
 
24
    Fact2_[i] = i*Fact_[i-2];
 
25
 
 
26
  BinomC_ = block_matrix(imax+1,imax+1);
 
27
  for(int n=0; n<=imax; n++)
 
28
    for(int m=0; m<=n; m++)
 
29
      BinomC_[n][m] = Fact_[n]/(Fact_[m]*Fact_[n-m]);
 
30
}
 
31
 
 
32
StatCombData::~StatCombData()
 
33
{
 
34
  delete[] Fact_;
 
35
  delete[] Fact2_;
 
36
  delete[] BinomC_;
 
37
}