Hello,
I am currently trying to solve the problem of fitting a known function to a given dataset of x, y, with y spanning a high range of values. Here's the snippet of code that needs consideration:
fit_params0= [35 1.11 1.7 RL0array(i_temp)];LB=[10 0.1 0.1 1000];UP=[1e+6 2 10 1e+12];fun=@(fit_params) norm (abs( ( A_const.*T(i_temp).*T(i_temp).*exp( -q_electron.*fit_params(2)./(k.*T(i_temp)) ).*S ).*( exp( q_electron.*(tempU2-tempI2.*fit_params(1))./( fit_params(3).*k.*T(i_temp) )) -1 ) ) + tempU2./fit_params(4) - tempI2 );fit_params=fminsearchbnd(fun,fit_params0, LB, UP, options);
x is tempU2 and y is tempI2.
fminsearchbnd is a modified version of fminsearch that enforces upper and lower bounds of variation parameters. fun calculates the absolute difference between the fitted y data and the given y data tempI2, takes the absolute values, then uses norm() to get a scalar from the resultant matrix.
Attached is a plot of the given data (blue line) compared to the plot of the fitted equation (blue dots):
Note that this is a logy graph. As you can see, the fit works great for high values of y… However, my y data ranges from 1E-3 to values as low as 1E-12.
My question, then, is how would I go about making fun() sensitive to scale after the difference between fitted y and given y is calculated? I do not want fminsearch to waste time looking at too many significant digits on high y scales.
I imagine something like multiplying matrix elements by their own scale during a second iteration of fminsearch would mitigate this problem? By that I mean, for example, if some calculated fun value would be 3.5E-5, it would then be multiplied by its own scale (E-5), to result in 3.5, giving the optimization problem equal weight on all scales.
Best Answer