# source:branches/parallel/Ipopt/contrib/RInterface/tests/banana.R@1887

Last change on this file since 1887 was 1887, checked in by andreasw, 3 years ago

synchronized with trunk rev 1886; fixed bug in Matrix-vector product for parallel matrix

File size: 1.6 KB
Line
2# This code is published under the Eclipse Public License.
3#
4# File:   banana.R
5# Author: Jelmer Ypma
6# Date:   18 April 2010
7#
8# Example showing how to solve the Rosenbrock Banana function.
9
10library('ipoptr')
11
12## Rosenbrock Banana function
13eval_f <- function(x) {
14    return( 100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2 )
15}
16
17## Gradient of Rosenbrock Banana function
19    return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
20                200 * (x[2] - x[1] * x[1])) )
21}
22
23# The Hessian for this problem is actually dense,
24# This is a symmetric matrix, fill the lower left triangle only.
25eval_h_structure <- list( c(1), c(1,2) )
26
27eval_h <- function( x, obj_factor, hessian_lambda ) {
28    return( obj_factor*c( 2 - 400*(x[2] - x[1]^2) + 800*x[1]^2,      # 1,1
29                          -400*x[1],                                 # 2,1
30                          200 ) )                                    # 2,2
31}
32
33# initial values
34x0 <- c( -1.2, 1 )
35
36opts <- list("print_level"=0,
37             "file_print_level"=12,
38             "output_file"="banana.out",
39             "tol"=1.0e-8)
40
41# solve Rosenbrock Banana function with analytic hessian
42print( ipoptr( x0=x0,
43               eval_f=eval_f,