[R] problems with constrained optimization

2013-08-19 Thread IliaN
I tried ti run a simple example with function solnp() from Rsolnp: find
max(x+y) on a unit circle x*x+y*y=1. The answer should be x=y=1/sqrt(2)
with max=sqrt(2).

Here are my code and results



 # test Rsolnp

 library(Rsolnp)

 fn1 - function(x)

+ {

+   x[1] + x[2]

+ }

 cond - function(x)

+ {

+  z- x[1]*x[1] + x[2]*x[2]

+ }

 x0 - c(0,1)

 cval - c(1)

 optim -solnp(x0,fun=fn1,eqfun=cond,eqB=cval)



Iter: 1 fn: 1.   Pars:  -3.053e-11  1.000e+00

solnp-- Completed in 1 iterations

 optim

$pars

[1] -3.053113e-11  1.00e+00



$convergence

[1] 0



$values

[1] 1 1



$lagrange

 [,1]

[1,]  0.5



$hessian

  [,1] [,2]

[1,] 2e+100

[2,] 0e+001



$ineqx0

NULL



$nfuneval

[1] 13



$outer.iter

[1] 1



$elapsed

Time difference of 0.00500083 secs



 

#

SOMETHING IS WRONG BUT I DO NOT SEE ANY MY MISTAKE. 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problems with constrained optimization

2013-08-19 Thread Erich Neuwirth
Bad starting value.
Try 
c(3/5,4/5)

On Aug 19, 2013, at 1:33 PM, il...@gertner.health.gov.il wrote:

 I tried ti run a simple example with function solnp() from Rsolnp: find
 max(x+y) on a unit circle x*x+y*y=1. The answer should be x=y=1/sqrt(2)
 with max=sqrt(2).
 
 Here are my code and results
 
 
 
 # test Rsolnp
 
 library(Rsolnp)
 
 fn1 - function(x)
 
 + {
 
 +   x[1] + x[2]
 
 + }
 
 cond - function(x)
 
 + {
 
 +  z- x[1]*x[1] + x[2]*x[2]
 
 + }
 
 x0 - c(0,1)
 
 cval - c(1)
 
 optim -solnp(x0,fun=fn1,eqfun=cond,eqB=cval)
 
 
 
 Iter: 1 fn: 1.   Pars:  -3.053e-11  1.000e+00
 
 solnp-- Completed in 1 iterations
 
 optim
 
 $pars
 
 [1] -3.053113e-11  1.00e+00
 
 
 
 $convergence
 
 [1] 0
 
 
 
 $values
 
 [1] 1 1
 
 
 
 $lagrange
 
 [,1]
 
 [1,]  0.5
 
 
 
 $hessian
 
  [,1] [,2]
 
 [1,] 2e+100
 
 [2,] 0e+001
 
 
 
 $ineqx0
 
 NULL
 
 
 
 $nfuneval
 
 [1] 13
 
 
 
 $outer.iter
 
 [1] 1
 
 
 
 $elapsed
 
 Time difference of 0.00500083 secs
 
 
 
 
 
 #
 
 SOMETHING IS WRONG BUT I DO NOT SEE ANY MY MISTAKE. 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.