MATLAB 'lsqcurvefit' returning NaN for certain parameter initializations in R2023b
I'm having trouble with I've been banging my head against this for hours... I've searched everywhere and can't find a clear answer. I'm using the `lsqcurvefit` function in MATLAB R2023b to fit a nonlinear model to my data, but I encounter an scenario where the function returns NaN for the optimized parameters when I provide certain initial guesses. My model is a simple exponential decay defined as: ```matlab model = @(b, x) b(1) * exp(-b(2) * x); ``` I have some experimental data in the form of vectors `xdata` and `ydata`, which I have plotted to visually confirm that my model is appropriate. However, when I initialize my parameters with a guess like `[1, 0.1]`, the function runs successfully, but if I set them to something like `[1, 10]`, I get the following warning: ``` Warning: The function value at the current point is not finite. ``` I've tried scaling my data and adjusting the bounds on the parameters. Hereβs the code I'm using: ```matlab xdata = [0, 1, 2, 3, 4]; ydata = [1, 0.7, 0.4, 0.1, 0]; initialGuess = [1, 10]; lowerBounds = [0, 0]; upperBounds = [Inf, Inf]; [beta, resnorm, residual, exitflag] = lsqcurvefit(model, initialGuess, xdata, ydata, lowerBounds, upperBounds); ``` When I check the residuals, they seem to be valid, but the optimization fails to converge. This behavior seems inconsistent because other initial guesses work fine. Can anyone guide to understand why certain initial values lead to NaN outputs? Are there best practices or transformations I should consider for initializing parameters in `lsqcurvefit`? I need to find a way to ensure that I can use a wider range of initial guesses without running into this scenario. This is part of a larger API I'm building. Am I missing something obvious? For context: I'm using Matlab on Linux. What am I doing wrong? I'd really appreciate any guidance on this. I'm developing on Ubuntu 20.04 with Matlab. Thanks for your help in advance!