Function containing imaginary unit 'i' returns 'object i not found' error when used to fit

34 Views Asked by At

I am trying to fit some data with a real and an imaginary component. To do this, I have set up the following function:

fitfunc <- function(R1, C1, R2, C2, W1, W2, g)(R1 + (i*freq*C1 + 1/R2)^-1 + (i*freq*C2 + (W1(i*freq*W2)^-g)*tanh((i*freq*W2)^g)^-1)^-1)

When I try to use this function to fit my data using nls() with the line shown below:

fit <- nls(Z ~  fitfunc(R1, C1, R2, C2, W1, W2, g), data = Zfreq, start = list(R1 = 10, C1 = 1e-6, R2 = 10, C2 = 1e-6, W1 = 10, W2 = 10, g = 0.5))

I get an error message saying 'Error in fitfunc(R1, C1, R2, C2, W1, W2, g) : object 'i' not found. How do I avoid this error? Any help would be really appreciated!:)

I'm quite new to r so am a bit stuck how to fit using functions with real and imaginary parts.

0

There are 0 best solutions below