0

This is a similar to question to Trilateration for n points and the enquirer has posted the answer since there were no answers.

From the parent post, the code is shown for Mathematica and has two variables (X,Y) in output.

I am having a difficulty in creating the same function in R using the nls function.

I have tried the following:

data <- data.frame( signal = c(98,94,66,49),x=c(6,5,4,4),y=c(6,7,7,6))   

weighted_distance <- function(signal, y, x)
{
   return(y - (signal^-1)*10*x)         
}

NLS_x <- nls(y ~ weighted_distance(signal,y,x), data = data,start = list(x=2,y=1))

I am getting the following error:

Error in numericDeriv(form[[3L]], names(ind), env) : 
'Missing value or an infinity produced when evaluating the model'

I understand that the formula written in the code is incorrect as the denominator is taken directly as the signal rather than multiplying with a constant signifying the distance.

But I do not understand how to proceed with the problem and represent it in a simpler way for the weighted non-linear squares estimation in R.

Community
  • 1
  • 1
KarthikS
  • 883
  • 1
  • 11
  • 17
  • Did you expect to get anything useful from `sin(acos(signal*x))` (which is equal to `sqrt(1-(signal*x)^2)`) when `signal*x > 1`? And, quoting from `?nls`: "If you wish to test ‘nls’ on artificial data please add a noise component, as shown in the example below." – Andy Barbour Sep 21 '15 at 06:05
  • Haha, thanks for pointing that out. Silly of me. I will change the function. I will also add some random component to it. – KarthikS Sep 21 '15 at 07:56

0 Answers0