@@ -80,6 +80,73 @@ using eigen_scalar_array2_t = std::vector<eigen_scalar_array_t>;
8080/* * Array of arrays of eigen scalar trajectory type. */
8181using eigen_scalar_array3_t = std::vector<eigen_scalar_array2_t >;
8282
83+ /* *
84+ * Defines the linear approximation
85+ * f(x,u) = dfdx' dx + dfdu' du + f
86+ */
87+ struct ScalarFunctionLinearApproximation {
88+ /* * First derivative w.r.t state */
89+ vector_t dfdx;
90+ /* * First derivative w.r.t input */
91+ vector_t dfdu;
92+ /* * Constant term */
93+ scalar_t f = 0 .;
94+
95+ /* * Default constructor */
96+ ScalarFunctionLinearApproximation () = default ;
97+
98+ /* * Construct and resize the members to given size. (Pass nu = -1 for no inputs) */
99+ explicit ScalarFunctionLinearApproximation (int nx, int nu = -1 );
100+
101+ /* * Compound addition assignment operator */
102+ ScalarFunctionLinearApproximation& operator +=(const ScalarFunctionLinearApproximation& rhs);
103+
104+ /* * Compound scalar multiplication and assignment operator */
105+ ScalarFunctionLinearApproximation& operator *=(scalar_t scalar);
106+
107+ /* *
108+ * Resize the members to the given size
109+ * @param[in] nx State dimension
110+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
111+ */
112+ ScalarFunctionLinearApproximation& resize (int nx, int nu = -1 );
113+
114+ /* *
115+ * Resizes the members to the given size, and sets all coefficients to zero.
116+ * @param[in] nx State dimension
117+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
118+ */
119+ ScalarFunctionLinearApproximation& setZero (int nx, int nu = -1 );
120+
121+ /* *
122+ * Factory function with zero initialization
123+ * @param[in] nx State dimension
124+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
125+ * @return Zero initialized object of given size.
126+ */
127+ static ScalarFunctionLinearApproximation Zero (int nx, int nu = -1 );
128+ };
129+
130+ std::ostream& operator <<(std::ostream& out, const ScalarFunctionLinearApproximation& f);
131+
132+ /* *
133+ * Checks the size of the given linear approximation.
134+ *
135+ * @param[in] stateDim: Number of states.
136+ * @param[in] inputDim: Number of inputs.
137+ * @param[in] data: Given quadratic approximation.
138+ * @param[in] dataName: The name of the data which appears in the output error message.
139+ * @return The description of the error. If there was no error it would be empty;
140+ */
141+ std::string checkSize (int stateDim, int inputDim, const ScalarFunctionLinearApproximation& data, const std::string& dataName);
142+
143+ inline ScalarFunctionLinearApproximation operator *(ScalarFunctionLinearApproximation lhs, scalar_t scalar) {
144+ return lhs *= scalar;
145+ }
146+ inline ScalarFunctionLinearApproximation operator *(scalar_t scalar, ScalarFunctionLinearApproximation rhs) {
147+ return rhs *= scalar;
148+ }
149+
83150/* *
84151 * Defines the quadratic approximation
85152 * f(x,u) = 1/2 dx' dfdxx dx + du' dfdux dx + 1/2 du' dfduu du + dfdx' dx + dfdu' du + f
@@ -101,8 +168,8 @@ struct ScalarFunctionQuadraticApproximation {
101168 /* * Default constructor */
102169 ScalarFunctionQuadraticApproximation () = default ;
103170
104- /* * Construct and resize the members to given size. */
105- ScalarFunctionQuadraticApproximation (size_t nx, size_t nu);
171+ /* * Construct and resize the members to given size. Pass nu = -1 for no inputs */
172+ explicit ScalarFunctionQuadraticApproximation (int nx, int nu = - 1 );
106173
107174 /* * Compound addition assignment operator */
108175 ScalarFunctionQuadraticApproximation& operator +=(const ScalarFunctionQuadraticApproximation& rhs);
@@ -113,24 +180,24 @@ struct ScalarFunctionQuadraticApproximation {
113180 /* *
114181 * Resize the members to the given size
115182 * @param[in] nx State dimension
116- * @param[in] nu Input dimension
183+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
117184 */
118- ScalarFunctionQuadraticApproximation& resize (size_t nx, size_t nu);
185+ ScalarFunctionQuadraticApproximation& resize (int nx, int nu = - 1 );
119186
120187 /* *
121188 * Resizes the members to the given size, and sets all coefficients to zero.
122189 * @param[in] nx State dimension
123- * @param[in] nu Input dimension
190+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
124191 */
125- ScalarFunctionQuadraticApproximation& setZero (size_t nx, size_t nu);
192+ ScalarFunctionQuadraticApproximation& setZero (int nx, int nu = - 1 );
126193
127194 /* *
128195 * Factory function with zero initialization
129196 * @param[in] nx State dimension
130- * @param[in] nu Input dimension
197+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
131198 * @return Zero initialized object of given size.
132199 */
133- static ScalarFunctionQuadraticApproximation Zero (size_t nx, size_t nu);
200+ static ScalarFunctionQuadraticApproximation Zero (int nx, int nu = - 1 );
134201};
135202
136203std::ostream& operator <<(std::ostream& out, const ScalarFunctionQuadraticApproximation& f);
@@ -184,33 +251,33 @@ struct VectorFunctionLinearApproximation {
184251 /* * Default constructor */
185252 VectorFunctionLinearApproximation () = default ;
186253
187- /* * Construct and resize the members to given size. */
188- VectorFunctionLinearApproximation (size_t nv, size_t nx, size_t nu);
254+ /* * Construct and resize the members to given size. (Pass nu = -1 for no inputs) */
255+ explicit VectorFunctionLinearApproximation (int nv, int nx, int nu = - 1 );
189256
190257 /* *
191258 * Resize the members to the given size
192259 * @param[in] nv Vector dimension
193260 * @param[in] nx State dimension
194- * @param[in] nu Input dimension
261+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
195262 */
196- VectorFunctionLinearApproximation& resize (size_t nv, size_t nx, size_t nu);
263+ VectorFunctionLinearApproximation& resize (int nv, int nx, int nu = - 1 );
197264
198265 /* *
199266 * Resizes the members to the given size, and sets all coefficients to zero.
200267 * @param[in] nv Vector dimension
201268 * @param[in] nx State dimension
202- * @param[in] nu Input dimension
269+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
203270 */
204- VectorFunctionLinearApproximation& setZero (size_t nv, size_t nx, size_t nu);
271+ VectorFunctionLinearApproximation& setZero (int nv, int nx, int nu = - 1 );
205272
206273 /* *
207274 * Factory function with zero initialization
208275 * @param[in] nv Vector dimension
209276 * @param[in] nx State dimension
210- * @param[in] nu Input dimension
277+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
211278 * @return Zero initialized object of given size.
212279 */
213- static VectorFunctionLinearApproximation Zero (size_t nv, size_t nx, size_t nu);
280+ static VectorFunctionLinearApproximation Zero (int nv, int nx, int nu = - 1 );
214281};
215282
216283std::ostream& operator <<(std::ostream& out, const VectorFunctionLinearApproximation& f);
@@ -250,32 +317,32 @@ struct VectorFunctionQuadraticApproximation {
250317 VectorFunctionQuadraticApproximation () = default ;
251318
252319 /* * Construct and resize the members to given size. */
253- VectorFunctionQuadraticApproximation (size_t nv, size_t nx, size_t nu);
320+ explicit VectorFunctionQuadraticApproximation (int nv, int nx, int nu = - 1 );
254321
255322 /* *
256323 * Resize the members to the given size
257324 * @param[in] nv Vector dimension
258325 * @param[in] nx State dimension
259- * @param[in] nu Input dimension
326+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
260327 */
261- VectorFunctionQuadraticApproximation& resize (size_t nv, size_t nx, size_t nu);
328+ VectorFunctionQuadraticApproximation& resize (int nv, int nx, int nu = - 1 );
262329
263330 /* *
264331 * Resizes the members to the given size, and sets all coefficients to zero.
265332 * @param[in] nv Vector dimension
266333 * @param[in] nx State dimension
267- * @param[in] nu Input dimension
334+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
268335 */
269- VectorFunctionQuadraticApproximation& setZero (size_t nv, size_t nx, size_t nu);
336+ VectorFunctionQuadraticApproximation& setZero (int nv, int nx, int nu = - 1 );
270337
271338 /* *
272339 * Factory function with zero initialization
273340 * @param[in] nv Vector dimension
274341 * @param[in] nx State dimension
275- * @param[in] nu Input dimension
342+ * @param[in] nu Input dimension (Pass nu = -1 for no inputs)
276343 * @return Zero initialized object of given size.
277344 */
278- static VectorFunctionQuadraticApproximation Zero (size_t nv, size_t nx, size_t nu);
345+ static VectorFunctionQuadraticApproximation Zero (int nv, int nx, int nu = - 1 );
279346};
280347
281348std::ostream& operator <<(std::ostream& out, const VectorFunctionQuadraticApproximation& f);
0 commit comments