# Help in R with Error: 'Cannot evaluate function at initial parameters

#### TobiD

##### New Member
Hello,

I have a really difficult topic (for me its difficult, because im a newbie in R).
I want to optimize a function so i can make a matrix between two coordinate Systems (Lab and RGB).

Here is my code:
Code:
setwd("C:/Users/Tobi_Laptop/Documents/Tobi/Studium/6. Semester/Farbmetrik/Projekt/Umrechnung")
Messwerte <- read.csv2("Messwerterot.csv", sep=";", dec=",")

DeltaL_lin1_fun <- function(Lab_Werte, par){with(Lab_Werte, sum((Messwerte$L99o.soll - (Messwerte$R*par+Messwerte$G*par + Messwerte$B*par))^2))}
L_lin1_opt <- optimx(par=c(1,1,1), fn=DeltaL_lin1_fun, Lab_Werte=Messwerte,mehtod="BGFS")

Deltaa_lin1_fun <- function(Lab_Werte, par){with(Lab_Werte, sum((Messwerte$a99o.soll - (Messwerte$R*par+Messwerte$G*par + Messwerte$B*par))^2))}
a_lin1_opt <- optimx(par=c(1,1,1), fn=Deltaa_lin1_fun, Lab_Werte=Messwerte,mehtod="BGFS")

Deltab_lin1_fun <- function(Lab_Werte, par){with(Lab_Werte, sum((Messwerte$b99o.soll - (Messwerte$R*par+Messwerte$G*par + Messwerte$B*par))^2))}
b_lin1_opt <- optimx(par=c(1,1,1), fn=Deltab_lin1_fun, Lab_Werte=Messwerte,mehtod="BGFS")

M_lin1<-matrix(c(L_lin1_opt$p1,L_lin1_opt$p2,L_lin1_opt$p3,a_lin1_opt$p1,a_lin1_opt$p2,a_lin1_opt$p3,b_lin1_opt$p1,b_lin1_opt$p2,b_lin1_opt$p3), nrow=3, byrow=TRUE) colnames(M_lin1)<-c("p1","p2","p3") rownames(M_lin1)<-c("L","a","b") M_lin1 The Line with L_lin_opt gets the Error: 'Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, : Cannot evaluate function at initial parameters'

Thanks for the fast answer I could not upload my RMD file or my original excel file to this site so you sadly not have the data.

Last edited by a moderator:

#### Dason

##### Ambassador to the humans
You need to write you function so that first input is par. You also misspelled "method" but I don't think that's the issue.