Skip to content
Back to formatted view

Raw Message

Message-ID: <loom.20041102T181946-920@post.gmane.org>
Date: 2004-11-02T17:20:36Z
From: Gabor Grothendieck
Subject: integer

Ludovic Tambour ludovic.tambour at cirad.fr 

: The problem is :
: " I have a numerical function y = f(x1,x2,x3) where x1...x3 are integers. I
: would like to determine x1,x2,x3 so that "y" has a minimal value. I know
: that
: R can determine a minimal value when x1,x2,x3 are real. Is-it possible to do
: this when x1, x2, x3 are restricted to be integers ? "

Will brute force do?

R> g <- expand.grid(x1 = 0:10, x2 = 0:10, x3 = 0:10)
R> f <- function(x) sum(x*x)
R> g[which.min(apply(g, 1, f)),]
  x1 x2 x3
1  0  0  0