ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat20.cpp
Go to the documentation of this file.
1 
9 #include "fvar.hpp"
10 
11 #ifdef __TURBOC__
12  #pragma hdrstop
13  #include <iostream.h>
14 #endif
15 
16 #ifdef __ZTC__
17  #include <iostream.hpp>
18 #endif
19 
20 #include <stdio.h>
21 #ifndef __SUN__
22 #endif
23 #include <math.h>
24 
25 // dmatrix mathematical functions
26 dmatrix exp(const dmatrix& m);
27 dmatrix log(const dmatrix& m);
28 dmatrix sin(const dmatrix& m);
29 dmatrix cos(const dmatrix& m);
30 dmatrix tan(const dmatrix& m);
31 dmatrix pow(const dmatrix& m, const double e);
32 dmatrix pow(const dmatrix& m,int e);
33 // end of dvar_vector mathematical functions
34 
35 /* "template form for editor
36 dmatrix XXX(const dmatrix& m)
37 {
38  ivector cmin(m.rowmin(),m.rowmax());
39  ivector cmax(m.rowmin(),m.rowmax());
40  for (int i=m.rowmin();i<=m.rowmax();i++)
41  {
42  cmin(i)=m(i).indexmin();
43  cmax(i)=m(i).indexmax();
44  }
45  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
46  for (i=m.rowmin();i<=m.rowmax();i++)
47  {
48  tmp(i)=XXX(m(i));
49  }
50  return tmp;
51 }
52 
53 */
54 
60 dmatrix pow(const dmatrix& m,int e)
61 {
62  ivector cmin(m.rowmin(), m.rowmax());
63  ivector cmax(m.rowmin(), m.rowmax());
64  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
65  {
66  cmin(i) = m(i).indexmin();
67  cmax(i) = m(i).indexmax();
68  }
69  dmatrix tmp(m.rowmin(), m.rowmax(), cmin, cmax);
70  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
71  {
72  tmp(i) = pow(m(i), e);
73  }
74  return tmp;
75 }
76 /*
77 Returns dmatrix with pow of each element in m raised to the exponent e.
78 \param m dmatrix
79 \param e floating point exponent
80 */
81 dmatrix pow(const dmatrix& m, const double e)
82 {
83  ivector cmin(m.rowmin(), m.rowmax());
84  ivector cmax(m.rowmin(), m.rowmax());
85  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
86  {
87  cmin(i) = m(i).indexmin();
88  cmax(i) = m(i).indexmax();
89  }
90  dmatrix tmp(m.rowmin(), m.rowmax(), cmin, cmax);
91  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
92  {
93  tmp(i) = pow(m(i), e);
94  }
95  return tmp;
96 }
97 
102 dmatrix tan(const dmatrix& m)
103 {
104  ivector cmin(m.rowmin(),m.rowmax());
105  ivector cmax(m.rowmin(),m.rowmax());
106  int i;
107  for (i=m.rowmin();i<=m.rowmax();i++)
108  {
109  cmin(i)=m(i).indexmin();
110  cmax(i)=m(i).indexmax();
111  }
112  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
113  for (i=m.rowmin();i<=m.rowmax();i++)
114  {
115  tmp(i)=tan(m(i));
116  }
117  return tmp;
118 }
119 
124 dmatrix cos(const dmatrix& m)
125 {
126  ivector cmin(m.rowmin(),m.rowmax());
127  ivector cmax(m.rowmin(),m.rowmax());
128  int i;
129  for (i=m.rowmin();i<=m.rowmax();i++)
130  {
131  cmin(i)=m(i).indexmin();
132  cmax(i)=m(i).indexmax();
133  }
134  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
135  for (i=m.rowmin();i<=m.rowmax();i++)
136  {
137  tmp(i)=cos(m(i));
138  }
139  return tmp;
140 }
141 
146 dmatrix sin(const dmatrix& m)
147 {
148  ivector cmin(m.rowmin(),m.rowmax());
149  ivector cmax(m.rowmin(),m.rowmax());
150  int i;
151  for (i=m.rowmin();i<=m.rowmax();i++)
152  {
153  cmin(i)=m(i).indexmin();
154  cmax(i)=m(i).indexmax();
155  }
156  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
157  for (i=m.rowmin();i<=m.rowmax();i++)
158  {
159  tmp(i)=sin(m(i));
160  }
161  return tmp;
162 }
163 
168 dmatrix elem_prod(const dmatrix& m, const dmatrix& m2)
169 {
170  ivector cmin(m.rowmin(),m.rowmax());
171  ivector cmax(m.rowmin(),m.rowmax());
172  int i;
173  for (i=m.rowmin();i<=m.rowmax();i++)
174  {
175  cmin(i)=m(i).indexmin();
176  cmax(i)=m(i).indexmax();
177  }
178  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
179  for (i=m.rowmin();i<=m.rowmax();i++)
180  {
181  tmp(i)=elem_prod(m(i),m2(i));
182  }
183  return tmp;
184 }
185 
190 dmatrix log(const dmatrix& m)
191 {
192  ivector cmin(m.rowmin(),m.rowmax());
193  ivector cmax(m.rowmin(),m.rowmax());
194  int i;
195  for (i=m.rowmin();i<=m.rowmax();i++)
196  {
197  cmin(i)=m(i).indexmin();
198  cmax(i)=m(i).indexmax();
199  }
200  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
201  for (i=m.rowmin();i<=m.rowmax();i++)
202  {
203  tmp(i)=log(m(i));
204  }
205  return tmp;
206 }
212 {
213  ivector cmin(m.rowmin(), m.rowmax());
214  ivector cmax(m.rowmin(), m.rowmax());
215  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
216  {
217  cmin(i) = m(i).indexmin();
218  cmax(i) = m(i).indexmax();
219  }
220  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
221  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
222  {
223  tmp(i) = sqrt(m(i));
224  }
225  return tmp;
226 }
231 dmatrix sqr(const dmatrix& m)
232 {
233  ivector cmin(m.rowmin(), m.rowmax());
234  ivector cmax(m.rowmin(), m.rowmax());
235  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
236  {
237  cmin(i) = m(i).indexmin();
238  cmax(i) = m(i).indexmax();
239  }
240  dmatrix tmp(m.rowmin(), m.rowmax(), cmin, cmax);
241  for (int i = m.rowmin(); i <= m.rowmax(); ++i)
242  {
243  tmp(i) = sqr(m(i));
244  }
245  return tmp;
246 }
247 
252 dmatrix exp(const dmatrix& m)
253 {
254  ivector cmin(m.rowmin(),m.rowmax());
255  ivector cmax(m.rowmin(),m.rowmax());
256  int i;
257  for (i=m.rowmin();i<=m.rowmax();i++)
258  {
259  cmin(i)=m(i).indexmin();
260  cmax(i)=m(i).indexmax();
261  }
262  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
263  for (i=m.rowmin();i<=m.rowmax();i++)
264  {
265  tmp(i)=exp(m(i));
266  }
267  return tmp;
268 }
269 
274 dmatrix elem_div(const dmatrix& m, const dmatrix& m2)
275 {
276  ivector cmin(m.rowmin(),m.rowmax());
277  ivector cmax(m.rowmin(),m.rowmax());
278  int i;
279  for (i=m.rowmin();i<=m.rowmax();i++)
280  {
281  cmin(i)=m(i).indexmin();
282  cmax(i)=m(i).indexmax();
283  }
284  dmatrix tmp(m.rowmin(),m.rowmax(),cmin,cmax);
285  for (i=m.rowmin();i<=m.rowmax();i++)
286  {
287  tmp(i)=elem_div(m(i),m2(i));
288  }
289  return tmp;
290 }
d3_array tan(const d3_array &arr3)
Returns d3_array results with computed tan from elements in arr3.
Definition: d3arr2a.cpp:73
d3_array sqr(const d3_array &arr3)
Returns d3_array with square values from arr3.
Definition: d3arr2c.cpp:25
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
Definition: d3arr2a.cpp:92
int indexmin() const
Definition: fvar.hpp:2917
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
Definition: d3arr2a.cpp:112
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
int rowmax() const
Definition: fvar.hpp:2929
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
Description not yet available.
Definition: fvar.hpp:2819
int indexmax() const
Definition: fvar.hpp:2921
d3_array cos(const d3_array &arr3)
Returns d3_array results with computed cos from elements in arr3.
Definition: d3arr2a.cpp:58
int rowmin() const
Definition: fvar.hpp:2925
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17