Search code examples
requation-solvingnlsmodel-fitting

nls: Nonlinear Least Squares: model fitting done, now get stuck at finding x (y=0)


I have a series of experimental rT and T. I am using nls to fit my data to this formula:

rT~exp(aa * T) - exp(aa * Tmax - (Tmax - T)/deltaT) + bb

The nls fitting returned an nls object and gave me the estimated parameters aa, bb, Tmax, deltaT in the predefined formula.

However now I am getting stuck with calculating the value T at which rT=0. In other words, I have to solve this equation to find T: exp(aa * T) - exp(aa * Tmax - (Tmax - T)/deltaT) + bb = 0 Can I get help from you with that task? Is there a way to calculate T (y-0) based on the best fit nls model that I got from the previous step?

Your help is much appreciated,


Solution

  • I think you can consider something like :

    aa <- 0.5
    Tmax <- 0.23
    deltaT <- 0.75
    bb <- 0.2
    
    fn <- function(t)
    {
      val <- exp(aa * t) - exp(aa * Tmax - (Tmax - t) / deltaT) + bb
      return(val ^ 2)
    }
    
    
    optimize(f = fn, interval = c(0, 100))