53 #ifndef ROL_LEASTSQUARES_HPP 54 #define ROL_LEASTSQUARES_HPP 71 typedef typename vector::size_type
uint;
75 Teuchos::RCP<const vector>
getVector(
const V& x ) {
76 using Teuchos::dyn_cast;
81 using Teuchos::dyn_cast;
92 Real h = 1.0/((Real)n+1.0);
95 for (uint i=0; i<n; i++) {
97 res = 2.0*h*(5.0/6.0) + 1.0/h*((*xp)[i+1]-2.0*(*xp)[i]);
99 else if ( i == n-1 ) {
100 res = 2.0*h*(5.0/6.0) + 1.0/h*((*xp)[i-1]-2.0*(*xp)[i]);
103 res = 2.0*h + 1.0/h*((*xp)[i-1]-2.0*(*xp)[i]+(*xp)[i+1]);
118 Real h = 1.0/((Real)n+1.0);
120 for (uint i=0; i<n; i++) {
122 res[i] = 2.0*h*(5.0/6.0) + 1.0/h*((*xp)[i+1]-2.0*(*xp)[i]);
124 else if ( i == n-1 ) {
125 res[i] = 2.0*h*(5.0/6.0) + 1.0/h*((*xp)[i-1]-2.0*(*xp)[i]);
128 res[i] = 2.0*h + 1.0/h*((*xp)[i-1]-2.0*(*xp)[i]+(*xp)[i+1]);
132 for (uint i=0; i<n; i++) {
134 (*gp)[i] = 1.0/h*(res[i+1]-2.0*res[i]);
136 else if ( i == n-1 ) {
137 (*gp)[i] = 1.0/h*(res[i-1]-2.0*res[i]);
140 (*gp)[i] = 1.0/h*(res[i-1]-2.0*res[i]+res[i+1]);
153 Real h = 1.0/((Real)n+1.0);
155 for (uint i=0; i<n; i++) {
157 res[i] = 1.0/h*((*vp)[i+1]-2.0*(*vp)[i]);
159 else if ( i == n-1 ) {
160 res[i] = 1.0/h*((*vp)[i-1]-2.0*(*vp)[i]);
163 res[i] = 1.0/h*((*vp)[i-1]-2.0*(*vp)[i]+(*vp)[i+1]);
167 for (uint i=0; i<n; i++) {
169 (*hvp)[i] = 1.0/h*(res[i+1]-2.0*res[i]);
171 else if ( i == n-1 ) {
172 (*hvp)[i] = 1.0/h*(res[i-1]-2.0*res[i]);
175 (*hvp)[i] = 1.0/h*(res[i-1]-2.0*res[i]+res[i+1]);
185 typedef std::vector<Real>
vector;
188 typedef typename vector::size_type
uint;
192 using Teuchos::dyn_cast;
195 RCP<vector> x0p = dyn_cast<SV>(x0).
getVector();
196 RCP<vector> xp = dyn_cast<SV>(x).
getVector();
207 for (uint i=0; i<n; i++) {
211 Real h = 1.0/((Real)n+1.0);
213 for( uint i=0; i<n; i++ ) {
215 (*xp)[i] = pt*(1.0-pt);
Provides the interface to evaluate objective functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Defines the linear algebra or vector space interface.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
std::vector< Real > vector
Provides the std::vector implementation of the ROL::Vector interface.
void getLeastSquares(Teuchos::RCP< Objective< Real > > &obj, Vector< Real > &x0, Vector< Real > &x)
Teuchos::RCP< vector > getVector(V &x)
Teuchos::RCP< const vector > getVector(const V &x)