[R] Optimize a function with Discrete inputs

Eik Vettorazzi E.Vettorazzi at uke.de
Wed Aug 1 16:23:06 CEST 2012


Hi,
not sure if that is what you are looking for, but have a look at

cmb<-t(combn(c(0,3,5,8),2))   #get all pairs of combinations
cbind(cmb,apply(cmb,1,diff))  #for each pair, get the difference

cheers


Am 01.08.2012 12:29, schrieb loyolite270:
> Hi
> 
> I need to optimize the below function:
> 
> a=function(x){
>      A=x[1]
>      B=x[2]
>      C=B-A
> return(C)
> }
> 
> I need to optimize the above function such that x can be any combination of
> these number (0,3,5,8) of vector length 2
> (i.e) x can be (3,0), (5,0), (8,0), (3,5), (3,8), (5,8), ...... etc
> 
> can someone please help me solve this problem ?
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimize-a-function-with-Discrete-inputs-tp4638644.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.
> 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 



More information about the R-help mailing list