| [eddd23a] | 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : FunC2.tol |
|---|
| 4 | // PURPOSE: Defines Class @FunC2 |
|---|
| 5 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 9 | Text _.autodoc.member.FunC2 = |
|---|
| 10 | "Abstract root class to handle with mutivariate functions R^n -> R of class " |
|---|
| 11 | "C2, ie, continuous and having first and second partial derivatives that are " |
|---|
| 12 | "also continuous. For efficience reasons the base evaluates over massive " |
|---|
| 13 | "arrays of points stored as rows in a matrix.\n"; |
|---|
| 14 | Class @FunC2 |
|---|
| 15 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 16 | { |
|---|
| 17 | VMatrix eval.function.v(VMatrix X); |
|---|
| 18 | VMatrix eval.partial.derivative.1.v(VMatrix X, Real i); |
|---|
| 19 | VMatrix eval.partial.derivative.2.v(VMatrix X, Real i, Real j); |
|---|
| 20 | |
|---|
| 21 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 22 | Real eval.function.r(VMatrix x) |
|---|
| 23 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 24 | { |
|---|
| 25 | MatDat(eval.function.v(x),1,1) |
|---|
| 26 | }; |
|---|
| 27 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 28 | Real eval.partial.derivative.1.r(VMatrix x, Real i) |
|---|
| 29 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 30 | { |
|---|
| 31 | MatDat(eval.partial.derivative.1.v(x,i),1,1) |
|---|
| 32 | }; |
|---|
| 33 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 34 | Real eval.partial.derivative.2.r(VMatrix x, Real i, Real j) |
|---|
| 35 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 36 | { |
|---|
| 37 | MatDat(eval.partial.derivative.2.v(x,i,j),1,1) |
|---|
| 38 | } |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 43 | Text _.autodoc.member.FunC2.InBaseC2 = |
|---|
| 44 | "Mutivariate functions R^n -> R of class C2 that is implemented as a linear " |
|---|
| 45 | "combination of the elemnets of a base of C2 functions R^n -> R, ie, an " |
|---|
| 46 | "instance of @BaseC2"; |
|---|
| 47 | Class @FunC2.InBaseC2 : @FunC2 |
|---|
| 48 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 49 | { |
|---|
| 50 | @BaseC2 _.base; |
|---|
| 51 | VMatrix _.linComb; |
|---|
| 52 | |
|---|
| 53 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 54 | Static Text _.autodoc.member.New = "Creates an specified instance of " |
|---|
| 55 | "@FunC2.InBaseC2"; |
|---|
| 56 | Static @FunC2.InBaseC2 New(@BaseC2 base, VMatrix linComb) |
|---|
| 57 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 58 | { |
|---|
| 59 | @FunC2.InBaseC2 aux = [[ |
|---|
| 60 | @BaseC2 _.base = base; |
|---|
| 61 | VMatrix _.linComb = linComb |
|---|
| 62 | ]]}; |
|---|
| 63 | |
|---|
| 64 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 65 | Static Text _.autodoc.member.Random = "Creates a random instance of " |
|---|
| 66 | "@FunC2.InBaseC2 of given norm"; |
|---|
| 67 | Static @FunC2.InBaseC2 Random(@BaseC2 base, Real norm) |
|---|
| 68 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 69 | { |
|---|
| 70 | VMatrix v = Gaussian(base::_.K,1,0,1); |
|---|
| 71 | VMatrix u = v*VMatDat(MtMSqr(v),1,1)^(-0.5); |
|---|
| 72 | New(base, u*norm) |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 76 | VMatrix eval.function.v(VMatrix X) |
|---|
| 77 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 78 | { |
|---|
| 79 | _.base::function.m(X)*_.linComb |
|---|
| 80 | }; |
|---|
| 81 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 82 | VMatrix eval.partial.derivative.1.v(VMatrix X, Real i) |
|---|
| 83 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 84 | { |
|---|
| 85 | _.base::partial.derivative.1.m(X,i)*_.linComb |
|---|
| 86 | }; |
|---|
| 87 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 88 | VMatrix eval.partial.derivative.2.v(VMatrix X, Real i, Real j) |
|---|
| 89 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 90 | { |
|---|
| 91 | _.base::partial.derivative.2.m(X,i,j)*_.linComb |
|---|
| 92 | } |
|---|
| 93 | }; |
|---|
| 94 | |
|---|