ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
orthply2.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <fvar.hpp>
12 
17 d4_array orthpoly2(int d1,int d2, int n,int m)
18 {
19  d4_array A(0,d1,0,d2,1,n,1,m);
20  d4_array B(0,d1,0,d2,1,n,1,m);
21  int alpha,beta,i,j,ii,jj;
22  int N=(1+d1)*(1+d2);
23  ivector ialpha(1,N);
24  ivector ibeta(1,N);
25 
26 
27  for (alpha=0;alpha<=d1;alpha++)
28  {
29  for (beta=0;beta<=d2;beta++)
30  {
31  for (i=1;i<=n;i++)
32  {
33  for (j=1;j<=m;j++)
34  {
35 #if defined(USE_DDOUBLE)
36 #undef double
37  A(alpha,beta,i,j)=pow(double(i-1)/double(n-1),alpha)*
38  pow(double(j-1)/double(m-1),beta);
39 #define double dd_real
40 #else
41  A(alpha,beta,i,j)=pow(double(i-1)/double(n-1),alpha)*
42  pow(double(j-1)/double(m-1),beta);
43 #endif
44  }
45  }
46  }
47  }
48  ii=1;
49  for (alpha=0;alpha<=d1;alpha++)
50  {
51  for (beta=0;beta<=d2;beta++)
52  {
53  ialpha(ii)=alpha;
54  ibeta(ii)=beta;
55  ii++;
56  }
57  }
58  for (ii=1;ii<=N;ii++)
59  {
60  //cout << "X" << endl;
61  if (ii>1)
62  {
63 //cout << dot(B(ialpha(ii-1),ibeta(ii-1)),A(ialpha(ii),ibeta(ii))) << endl;
64  //cout << dot(B(ialpha(ii-1),ibeta(ii-1)),
65  // A(ialpha(ii),ibeta(ii))/norm(A(ialpha(ii),ibeta(ii)))) << endl;
66  }
67  B(ialpha(ii),ibeta(ii))=A(ialpha(ii),ibeta(ii))/
68  norm(A(ialpha(ii),ibeta(ii)));
69  //if (ii>1)
70 // cout << dot(B(ialpha(ii-1),ibeta(ii-1)),B(ialpha(ii),ibeta(ii))) << endl;
71  //cout << "Y" << endl;
72  for (jj=ii+1;jj<=N;jj++)
73  {
74  A(ialpha(jj),ibeta(jj))-=
75  dot(B(ialpha(ii),ibeta(ii)),A(ialpha(jj),ibeta(jj)))*
76  B(ialpha(ii),ibeta(ii));
77  //cout << dot(B(ialpha(ii),ibeta(ii)),A(ialpha(jj),ibeta(jj))) << endl;
78  }
79  //cout << "Z" << endl;
80  }
81  return B;
82 }
83 
88 double dot(const dmatrix& M,const dmatrix& N)
89 {
90  int mmin=M.indexmin();
91  int mmax=M.indexmax();
92  if (mmin!=N.indexmin() ||
93  mmax!=N.indexmax() )
94  {
95  cerr << "matrix shapes unequal in"
96  " double dot(const dmatrix& M,const dmatrix& N)"
97  << endl;
98  ad_exit(1);
99  }
100  if (M(mmin).indexmin()!=N(mmin).indexmin() ||
101  M(mmin).indexmax()!=N(mmin).indexmax() )
102  {
103  cerr << "matrix shapes unequal in"
104  " double dot(const dmatrix& M,const dmatrix& N)"
105  << endl;
106  ad_exit(1);
107  }
108  double ssum=0;
109  for (int i=mmin;i<=mmax;i++)
110  {
111  int jmin=M(i).indexmin();
112  int jmax=M(i).indexmax();
113  for (int j=jmin;j<=jmax;j++)
114  {
115  ssum+=M(i,j)*N(i,j);
116  }
117  }
118  return ssum;
119 }
#define N
Definition: rngen.cpp:56
int indexmin() const
Definition: fvar.hpp:2917
exitptr ad_exit
Definition: gradstrc.cpp:53
double norm(const d3_array &a)
Return computed norm value of a.
Definition: d3arr2a.cpp:190
Description not yet available.
Definition: fvar.hpp:5161
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
#define M
Definition: rngen.cpp:57
dvariable beta(const prevariable &a, const prevariable &b)
Beta density function.
Definition: vbeta.cpp:18
Description not yet available.
Definition: fvar.hpp:2819
int indexmax() const
Definition: fvar.hpp:2921
double dot(const dmatrix &M, const dmatrix &d2)
Description not yet available.
Definition: orthply2.cpp:88
d4_array orthpoly2(int n, int m, int d1, int d2)
Description not yet available.
Definition: orthply2.cpp:17
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17