30 _value[0] = 3*x[0]*x[0]*x[1] + 2*sqrt(x[2])/x[0];
36 _jacobian(0,0) = 6*x[0]*x[1] - 2*sqrt(x[2])/(x[0]*x[0]);
37 _jacobian(0,1) = 3*x[0]*x[0];
38 _jacobian(0,2) = 1/(x[0]*sqrt(x[2]));
51 H(0,0) = 6*x[1] + 4*sqrt(x[2])/(x[0]*x[0]*x[0]);
52 H(0,1) = H(1,0) = 6*x[0];
53 H(0,2) = H(2,0) = -1/(x[0]*x[0]*sqrt(x[2]));
56 H(2,2) = -1/(2*x[0]*x[2]*sqrt(x[2]));
63 throw std::runtime_error(
"[Function1::doResize] Variable x size is different from 3");
75 xyz.
setValue(Vector3d(0.1,-0.2,0.45));
76 std::cout <<
"f(0.1,-0.2,0.45) = " << f1.
getValue() << std::endl << std::endl;
77 std::cout <<
"df/dx(0.1,-0.2,0.45) = " << std::endl << f1.
getJacobian() << std::endl << std::endl;
78 std::cout <<
"d2f/dx2(0.1,-0.2,0.45) = " << std::endl << f1.
get<
PARTIAL_XX>(0) << std::endl << std::endl << std::endl;
81 xyz.
setValue(Vector3d(0.324,0.12,0.06));
82 std::cout <<
"f(0.324,0.12,0.06) = " << f1.
getValue() << std::endl << std::endl;
83 std::cout <<
"df/dx(0.324,0.12,0.06) = " << std::endl << f1.
getJacobian() << std::endl << std::endl;
84 std::cout <<
"d2f/dx2(0.324,0.12,0.06) = " << std::endl << f1.
get<
PARTIAL_XX>(0) << std::endl << std::endl;
91 std::cout <<
"Can't compute partial_t" << std::endl;
95 std::cout << cstr.getDimension() << std::endl;
96 std::cout << cstr.getValue() << std::endl;
97 std::cout << cstr.get<
PARTIAL_XX>(0) << std::endl;
98 cstr.setB(VectorXd::Random(1));
99 std::cout << cstr.isValid<
FUN_VALUE>() << std::endl;
100 std::cout << cstr.isRespected() << std::endl;
102 std::cout << cstr.getType() << std::endl;
130 for (
int i=0; i<x.getSize(); ++i)
132 _value[0] = std::pow(std::abs(_value[0]),1./x.getSize());
138 double v = getValue(0)/x.getSize();
139 for (
int i=0; i<x.getSize(); ++i)
140 _jacobian(0,i) = v/x[i];
160 VectorXd tmp = getJacobian()*
static_cast<VectorXd
>(x_dot);
161 double v = getValue(0);
162 MatrixXd q =
static_cast<VectorXd
>(x).array().inverse().transpose();
164 Jdot.array() -= v*(
static_cast<VectorXd
>(x_dot)).transpose().array()*q.array()*q.array();
165 Jdot *= 1./x.getSize();
171 VectorXd q =
static_cast<VectorXd
>(x).array().inverse();
172 H = (x.getSize()*q.array()*q.array()).matrix().asDiagonal();
173 H -= q*q.transpose();
174 H *= -getValue(0)/(x.getSize()*x.getSize());
198 VectorXd v(size), dv(size), ddv(size);
199 v << -0.997497, 0.127171, -0.613392, 0.617481, 0.170019, -0.0402539, -0.299417, 0.791925;
200 dv << 0.64568 , 0.49321 , -0.651784, 0.717887, 0.421003, 0.0270699, -0.39201 , -0.970031;
201 ddv << -0.817194, -0.271096, -0.705374, -0.668203, 0.97705 , -0.108615 , -0.761834, -0.990661;
205 std::cout <<
"at x=" <<
static_cast<VectorXd
>(x).transpose() << std::endl;
206 std::cout <<
"at dot{x}=" <<
static_cast<VectorXd
>(x_dot).transpose() << std::endl;
207 std::cout <<
"at dot{x}=" <<
static_cast<VectorXd
>(x_ddot).transpose() << std::endl << std::endl;
211 std::cout <<
"f(x) = " << std::endl << f2.
getValue() << std::endl << std::endl;
216 std::cout <<
"df/dx(x) = " << std::endl << f2.
getJacobian() << std::endl << std::endl;
221 std::cout <<
"df/dt(x) = " << std::endl << f2.
get<
PARTIAL_T>() << std::endl << std::endl;
226 std::cout <<
"dot{f}(x) = " << std::endl << f2.
get<
FUN_DOT>() << std::endl << std::endl;
231 std::cout <<
"dot{df/dx}(x) = " << std::endl << f2.
get<
PARTIAL_X_DOT>() << std::endl << std::endl;
243 std::cout <<
"d2f/dx2(x) = " << std::endl << f2.
get<
PARTIAL_XX>(0) << std::endl << std::endl;
248 std::cout <<
"ddot{f}(x) = " << std::endl << f2.
get<
FUN_DDOT>() << std::endl << std::endl;
251 x.
setValue(Vector3d(-0.11,0.231,0.406));
252 std::cout <<
"at x=" <<
static_cast<VectorXd
>(x).transpose() << std::endl;
253 std::cout <<
"f(x) = " << std::endl << f2.
getValue() << std::endl << std::endl;
270 static std::vector<bool> allAbilitiesUpTo(
eFunctionAbility a) {
return std::vector<bool>(a+1,
true);}
280 , t(0), _t0(0), _stateX(Vector3d::Zero()), _stateY(Vector3d::Zero()), _stateZ(Vector3d::Zero())
288 void changeInitialState(
double t0,
const Vector3d& stateX,
const Vector3d& stateY,
const Vector3d& stateZ)
306 Vector3d v(1,dt,dt*dt/2);
307 double f = dt*dt*dt/6;
308 _value[0] = v.dot(_stateX) + x[0]*f;
309 _value[1] = v.dot(_stateY) + x[1]*f;
310 _value[2] = v.dot(_stateZ) + x[2]*f;
316 double f = dt*dt*dt/6;
317 _jacobian.setIdentity();
318 _jacobian.diagonal() *= f;
372 if (x.getSize() != 3)
373 throw std::runtime_error(
"[Function3::doResize] Variable x size is different from 3");
397 xyz.
setValue(Vector3d(0.1,-0.2,0.45));
398 xyz_dot.
setValue(Vector3d(0.03,0.15,-0.307));
399 xyz_ddot.
setValue(Vector3d(-0.008,-0.024,-0.022));
403 std::cout <<
"f = " << f3.
getValue() << std::endl << std::endl;
404 std::cout <<
"df/dx = " << std::endl << f3.
getJacobian() << std::endl << std::endl;
405 std::cout <<
"df/dt = " << std::endl << f3.
get<
PARTIAL_T >() << std::endl << std::endl;
406 std::cout <<
"fdot = " << std::endl << f3.
get<
FUN_DOT >() << std::endl << std::endl;
407 std::cout <<
"dot{df/dx} = " << std::endl << f3.
get<
PARTIAL_X_DOT>() << std::endl << std::endl;
408 std::cout <<
"d2f/dx2 = " << std::endl << f3.
get<
PARTIAL_XX >(0) << std::endl << std::endl
411 std::cout <<
"fddot = " << std::endl << f3.
get<
FUN_DDOT >() << std::endl << std::endl;
412 std::cout <<
"d2f/dt2 = " << std::endl << f3.
get<
PARTIAL_TT >() << std::endl << std::endl;
413 std::cout <<
"d2f/dtdx = " << std::endl << f3.
get<
PARTIAL_TX >() << std::endl << std::endl;
414 std::cout <<
"d2f/dxdt = " << std::endl << f3.
get<
PARTIAL_XT >() << std::endl << std::endl;
415 std::cout <<
"dot{df/dt} = " << std::endl << f3.
get<
PARTIAL_T_DOT>() << std::endl << std::endl;
422 std::cout <<
"**********************************************" << std::endl;
423 std::cout <<
"************ Example 1 ***************" << std::endl;
424 std::cout <<
"**********************************************" << std::endl;
427 std::cout << std::endl << std::endl;
428 std::cout <<
"**********************************************" << std::endl;
429 std::cout <<
"************ Example 2 ***************" << std::endl;
430 std::cout <<
"**********************************************" << std::endl;
433 std::cout << std::endl << std::endl;
434 std::cout <<
"**********************************************" << std::endl;
435 std::cout <<
"************ Example 3 ***************" << std::endl;
436 std::cout <<
"**********************************************" << std::endl;
void updateHessian() const
Computation ability of a ocra function.
virtual Variable & getTimeDerivative()
Get the time derivative/primitive of the variable.
void updatePartialTT() const
void updateHessian() const
void updateJacobian() const
void updateJacobian() const
void setValue(const VectorXd &value)
A set of tutorial/test for the Function class.
void updateHessian() const
eFunctionAbility
Enumeration of the computation abilities of a ocra function.
void changeInitialState(double t0, const Vector3d &stateX, const Vector3d &stateY, const Vector3d &stateZ)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
void updatePartialTX() const
const IFunction< Ability >::return_type & get() const
const MatrixXd & getJacobian() const
void updatePartialT() const
void doUpdateInputSizeBegin()
This class represents a variable in a mathematical sense.
void doUpdateInputSizeBegin()
const VectorXd & getValue() const
void updatePartialTdot() const
void updatePartialT() const
void doUpdateInputSizeEnd()
Declaration file of the Constraint class.
void resize(size_t newSize)
BaseVariable & getTimeDerivative()
Get the time derivative/primitive of the variable.
void updateJacobian() const
#define ocra_assert(ocra_expression)
Implements a basic variable.
void doUpdateInputSizeBegin()
void updatePartialXT() const