ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dvect6.cpp
Go to the documentation of this file.
1 
6 #include "fvar.hpp"
7 #include <cmath>
8 
9 #ifdef __TURBOC__
10  #pragma hdrstop
11 #endif
12 
13 void shape_check(const dvector& v1, const dvector& v2,
14  const char *function_name);
15 
21 dvector sin(const dvector& vec)
22 {
23  int min = vec.indexmin();
24  int max = vec.indexmax();
25  dvector results(min, max);
26  double* presultsi = results.get_v() + min;
27  double* pveci = vec.get_v() + min;
28  for (int i = min; i <= max; ++i)
29  {
30  *presultsi = std::sin(*pveci);
31 
32  ++presultsi;
33  ++pveci;
34  }
35  return results;
36 }
42 dvector cos(const dvector& vec)
43 {
44  int min = vec.indexmin();
45  int max = vec.indexmax();
46  dvector results(min, max);
47  double* presultsi = results.get_v() + min;
48  double* pveci = vec.get_v() + min;
49  for (int i = min; i <= max; ++i)
50  {
51  *presultsi = std::cos(*pveci);
52 
53  ++presultsi;
54  ++pveci;
55  }
56  return results;
57 }
63 dvector tan(const dvector& vec)
64 {
65  int min = vec.indexmin();
66  int max = vec.indexmax();
67  dvector results(min, max);
68  double* presultsi = results.get_v() + min;
69  double* pveci = vec.get_v() + min;
70  for (int i = min; i <= max; ++i)
71  {
72  *presultsi = std::tan(*pveci);
73 
74  ++presultsi;
75  ++pveci;
76  }
77  return results;
78 }
84 dvector sinh(const dvector& vec)
85 {
86  int min = vec.indexmin();
87  int max = vec.indexmax();
88  dvector results(min, max);
89  double* presultsi = results.get_v() + min;
90  double* pveci = vec.get_v() + min;
91  for (int i = min; i <= max; ++i)
92  {
93  *presultsi = std::sinh(*pveci);
94 
95  ++presultsi;
96  ++pveci;
97  }
98  return results;
99 }
105 dvector cosh(const dvector& vec)
106 {
107  int min = vec.indexmin();
108  int max = vec.indexmax();
109  dvector results(min, max);
110  double* presultsi = results.get_v() + min;
111  double* pveci = vec.get_v() + min;
112  for (int i = min; i <= max; ++i)
113  {
114  *presultsi = std::cosh(*pveci);
115 
116  ++presultsi;
117  ++pveci;
118  }
119  return results;
120 }
126 dvector tanh(const dvector& vec)
127 {
128  int min = vec.indexmin();
129  int max = vec.indexmax();
130  dvector results(min, max);
131  double* presultsi = results.get_v() + min;
132  double* pveci = vec.get_v() + min;
133  for (int i = min; i <= max; ++i)
134  {
135  *presultsi = std::tanh(*pveci);
136 
137  ++presultsi;
138  ++pveci;
139  }
140  return results;
141 }
149 dvector pow(const dvector& bases, const double exponent)
150 {
151  int min = bases.indexmin();
152  int max = bases.indexmax();
153  dvector results(min, max);
154  double* presultsi = results.get_v() + min;
155  double* pbasesi = bases.get_v() + min;
156  for (int i = min; i <= max; ++i)
157  {
158  *presultsi = std::pow(*pbasesi, exponent);
159 
160  ++presultsi;
161  ++pbasesi;
162  }
163  return results;
164 }
172 dvector pow(const dvector& bases, int exponent)
173 {
174  int min = bases.indexmin();
175  int max = bases.indexmax();
176  dvector results(min, max);
177  double* presultsi = results.get_v() + min;
178  double* pbasesi = bases.get_v() + min;
179  for (int i = min; i <= max; ++i)
180  {
181  *presultsi = std::pow(*pbasesi, exponent);
182 
183  ++presultsi;
184  ++pbasesi;
185  }
186  return results;
187 }
195 dvector pow(const dvector& bases, const dvector& exponents)
196 {
197  shape_check(bases, exponents,
198  "dvector pow(const dvector& bases ,constdvector& exponents)");
199 
200  dvector results(bases.indexmin(), bases.indexmax());
201  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
202  {
203  results.elem(i) = std::pow(bases.elem(i), exponents.elem(i));
204  }
205  return results;
206 }
214 dvector pow(const double base, const dvector& exponents)// ***
215 {
216  dvector results(exponents.indexmin(), exponents.indexmax());
217  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
218  {
219  results.elem(i) = std::pow(base, exponents.elem(i));
220  }
221  return results;
222 }
229 dvector asin(const dvector& vec)
230 {
231  dvector results(vec.indexmin(), vec.indexmax());
232  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
233  {
234  results.elem(i) = std::asin(vec.elem(i));
235  }
236  return results;
237 }
244 dvector acos(const dvector& vec)
245 {
246  dvector results(vec.indexmin(), vec.indexmax());
247  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
248  {
249  results.elem(i) = std::acos(vec.elem(i));
250  }
251  return results;
252 }
259 dvector atan(const dvector& vec)
260 {
261  dvector results(vec.indexmin(), vec.indexmax());
262  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
263  {
264  results.elem(i) = std::atan(vec.elem(i));
265  }
266  return results;
267 }
273 dvector log10(const dvector& vec)
274 {
275  dvector results(vec.indexmin(), vec.indexmax());
276  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
277  {
278  results.elem(i) = std::log10(vec.elem(i));
279  }
280  return results;
281 }
287 dvector sqrt(const dvector& vec)
288 {
289  dvector results(vec.indexmin(), vec.indexmax());
290  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
291  {
292  results.elem(i) = std::sqrt(vec.elem(i));
293  }
294  return results;
295 }
301 dvector sqr(const dvector& vec)
302 {
303  dvector results(vec.indexmin(), vec.indexmax());
304  for (int i = results.indexmin(); i <= results.indexmax(); ++i)
305  {
306  double x = vec.elem(i);
307  results.elem(i) = x * x;
308  }
309  return results;
310 }
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
dvector log10(const dvector &vec)
Returns dvector with the common (base-10) logarithm of vec.
Definition: dvect6.cpp:273
double & elem(int i)
Definition: dvector.h:152
dvector tanh(const dvector &vec)
Returns dvector with hyperbolic tangent for each value of vec.
Definition: dvect6.cpp:126
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
df1_one_variable atan(const df1_one_variable &x)
Definition: df11fun.cpp:312
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
dvector cosh(const dvector &vec)
Returns dvector with hyperbolic cosine for each value of vec.
Definition: dvect6.cpp:105
void shape_check(const dvector &a, const dvector &b, const char *message)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dvect18.cpp:26
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d3_array cos(const d3_array &arr3)
Returns d3_array results with computed cos from elements in arr3.
Definition: d3arr2a.cpp:58
dvector sinh(const dvector &vec)
Returns dvector with hyperbolic sine for each value of vec.
Definition: dvect6.cpp:84
#define max(a, b)
Definition: cbivnorm.cpp:189
double *& get_v(void)
Definition: dvector.h:148
dvector acos(const dvector &vec)
Returns dvector with principal value of the arc cosine of vec, expressed in radians.
Definition: dvect6.cpp:244
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17
dvector asin(const dvector &vec)
Returns dvector with principal value of the arc sine of vec, expressed in radians.
Definition: dvect6.cpp:229