Hi MATLAB community,
My question is similar to this one, but I still cannot figure out how to apply that solution (if even possible) to my problem.
I am using lsqnonlin to find the best fit of a function with specific parameters to a dataset ("data"). This is working, but after visual inspection of my results, I would now like to force the difference between the sum of three of the parameters (exponential amplitude 1, exponential amplitude 2, and the DC offset), and the first data point, to be within +/- the standard deviation of the data - perhaps easier to understand in this mathematical equation:
abs(expAmp1+expAmp2+DCoffs-data(1)) <= std(data)
Hence, I would like to add this into my code so that the fit results don't violate this boundary condition, but I have yet to figure out how to. Let's assume for simplicity's sake that I am fitting my data to only two exponential decays and a DC offset, with an objective function like so:
function diff = objFunc(param,time,data)
I can make boundary conditions for the individual parameters, but I cannot figure out how/where I could include a boundary condition that combines three of the parameters, similar to this:
abs(param(1)+param(3)+param(5)-data(1)) <= std(data)
I've spent hours searching MATLAB Answers, reading the lsqnonlin documentation, and trying to logically come up with a solution, but I just can't figure it out on my own.
Your help would be so greatly appreciated! Thank you!