source: tol/tol_pkg/FunRn2R/BaseC2.Monomial.tol @ eddd23a

1941-docker-image-to-testdevel
Last change on this file since eddd23a was eddd23a, checked in by Víctor de Buen <vdebuen@…>, 17 years ago

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1751 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/* -*- mode: C++ -*- */
2//////////////////////////////////////////////////////////////////////////////
3// FILE   : BaseC2.Monomial.tol
4// PURPOSE: Defines class @BaseC2.Monomial
5//////////////////////////////////////////////////////////////////////////////
6
7//////////////////////////////////////////////////////////////////////////////
8Text _.autodoc.member.BaseC2.Monomial = "Base of K mutivariate monomial "
9  "functions R^n -> R . Linear independence is ensured since distinct "
10  "monomials are allways independent\n";
11Class @BaseC2.Monomial : @BaseC2
12//////////////////////////////////////////////////////////////////////////////
13{
14  //Maximum degree of the monomial: sum of degrees of all variables
15  Real _.maxDeg;
16
17  ////////////////////////////////////////////////////////////////////////////
18  // Auxiliar memebers
19  ////////////////////////////////////////////////////////////////////////////
20
21  //Combination of degrees for each basic function
22  Set  _.degComb;
23  //Indexes for derivatives {1,...,n} - {i}
24  Set  _.range.der.1;
25  //Indexes for second derivatives {1,...,n} - {i,j}
26  Set  _.range.der.2;
27
28  ////////////////////////////////////////////////////////////////////////////
29  Static Text _.autodoc.member.New = "Creates an instance of "
30  "@BaseC2.Monomial on R^n with specified maximum degree.";
31  Static @BaseC2.Monomial New(Real n, Real maxDeg)
32  ////////////////////////////////////////////////////////////////////////////
33  {
34    VMatrix degCombAll = Mat2VMat(SetMat(Range(0,maxDeg,1)^n));
35    VMatrix degSum = degCombAll*Rand(n,1,1,1);
36    VMatrix match = LE(degSum,Rand(VRows(degCombAll),1,maxDeg,maxDeg));
37    Set select = MatQuery::SelectMatch(match);
38    Set degComb = VMat2Set(SubRow(degCombAll, select));
39    Real K = Card(degComb);
40    Set range.der.1 = For(1,n,Set(Real i)
41    {
42      Range(1,n,1)-[[i]]
43    });
44    Set range.der.2 = For(1,n,Set(Real i)
45    {
46      For(1,n,Set(Real j)
47      {
48        Range(1,n,1)-[[i,j]]
49      })
50    });
51    @BaseC2.Monomial aux = [[
52      Real _.n = n;
53      Real _.K = K;
54      Real _.maxDeg = maxDeg;
55      Set _.degComb = degComb;
56      Set _.range.der.1 = range.der.1;
57      Set _.range.der.2 = range.der.2
58  ]]};
59
60  ////////////////////////////////////////////////////////////////////////////
61  Static Text _.autodoc.member._build.function.v =
62  "Evaluates the k-th basic function for an "
63  "array of points given as the rows of a matrix ";
64  VMatrix _build.function.v(Real k, VMatrix X)
65  ////////////////////////////////////////////////////////////////////////////
66  {
67  //WriteLn("TRACE @BaseC2.Monomial::_build.function.2.v");
68    BinGroup("$*", For(1,_.n, VMatrix(Real i)
69    {
70      RPow(SubCol(X,[[i]]),_.degComb[k][i])
71    }))
72  };
73  ////////////////////////////////////////////////////////////////////////////
74  Static Text _.autodoc.member._build.partial.derivative.1.v =
75  "Evaluates the first partial derivative of k-th basic function for an "
76  "array of points given as the rows of a matrix";
77  VMatrix _build.partial.derivative.1.v(Real k, VMatrix X, Real i)
78  ////////////////////////////////////////////////////////////////////////////
79  {
80  //WriteLn("TRACE @BaseC2.Monomial::_build.partial.derivative.1.v");
81    Real d = _.degComb[k][i];
82    If(d==0, Rand(VRows(X),1,0,0),
83    {
84      VMatrix aux = (RPow(SubCol(X,[[i]]),d-1)*d);
85      If(!Card(_.range.der.1[i]),aux,aux $*
86      BinGroup("$*", EvalSet(_.range.der.1[i], VMatrix rd1(Real h)
87      {
88        RPow(SubCol(X,[[h]]),_.degComb[k][h])
89      })))
90    })
91  };
92  ////////////////////////////////////////////////////////////////////////////
93  Static Text _.autodoc.member._build.partial.derivative.2.v =
94  "Evaluates the second partial derivative of k-th basic function for an "
95  "array of points given as the rows of a matrix";
96  VMatrix _build.partial.derivative.2.v(Real k, VMatrix X, Real i, Real j)
97  ////////////////////////////////////////////////////////////////////////////
98  {
99  //WriteLn("TRACE @BaseC2.Monomial::_build.partial.derivative.2.v");
100    If(i==j,
101    {
102      Real d = _.degComb[k][i];
103      If(d<=1, Rand(VRows(X),1,0,0),
104      {
105        VMatrix aux = (RPow(SubCol(X,[[i]]),d-2)*((d-1)*d));
106        If(!Card(_.range.der.1[i]),aux,aux $*
107        BinGroup("$*", EvalSet(_.range.der.1[i], VMatrix rd21(Real h)
108        {
109          RPow(SubCol(X,[[h]]),_.degComb[k][h])
110        })))
111      })
112    },
113    {
114      Real d.i = _.degComb[k][i];
115      Real d.j = _.degComb[k][j];
116      If(Or(d.i==0, d.j==0), Rand(VRows(X),1,0,0),
117      {
118        VMatrix aux = (RPow(SubCol(X,[[i]]),d.i-1)*d.i) $*
119                      (RPow(SubCol(X,[[j]]),d.j-1)*d.j);
120        If(!Card(_.range.der.2[i][j]),aux,aux $*
121        BinGroup("$*", EvalSet(_.range.der.2[i][j], VMatrix rd22(Real h)
122        {
123          RPow(SubCol(X,[[h]]),_.degComb[k][h])
124        })))
125      })
126    })
127  }
128
129};
Note: See TracBrowser for help on using the repository browser.