I have posted a similar question on the earlier post. This post consist of another question i would like to ask.
Currently, I am using curve fitting toolbox to determine the parameters using the optimization of an custom equation containing parameters to the curve plotted using a set of data points.
I have few questions regarding the curve fitting toolbox that any help would be greatly appreciated.
1) The equation to determine the parameters are as shown in the following, where a and b are the parameters. Based on the criteria of my function, a should be within 0.024 to 0.054. Hence, for the setting of a, i've set it to be 0.024 or 0.054.
The final result for a should be 0.026.
And b should be within the 1e-9 to 1e-15. Whereby the result should be 1e-13.
However, instead of obtaining a=0.026, b=1e-13, i got the result as shown in the following. And from the observation of the fitted curve and data points, both curve does not conicide together.
Would like to consult, why does this occurs and how do i avoid the result of coefficient to be fixed at bound? Also, what should i do in order to get my result?
Following is the result obtained from the curve fitting toolbox.
----------------------------------------------------------------------------------------------------------------------
Fit computation did not converge:
Fitting stopped because the number of iterations or function evaluations exceeded the specified maximum.
Fit found when optimization terminated:
General model:
f(x) = a*((log(x/b))-((x(1)/x*(x(1)/b))))
Coefficients (with 95% confidence bounds):
a = 0.054 (fixed at bound)
b = 1.171e+006 (-9.023e+007, 9.257e+007)
Goodness of fit:
SSE: 5428
R-square: 0.03254
Adjusted R-square: 0.03254
RMSE: 12.45
-------------------------------------------------------------------------------------------------------------------------
2) I have a custom equation where the function is describe by y=f(x,y). Where the variables are non separable. When I apply the the equation to fit a set of data with y=f(x,y), the error indicated that y cannot be part of the custom equation. I would like to ask if there is anyone could give me an idea how do i input such equation? Following is the equation i would like to optimize to a set of data points:
y=1e-13(exp((x-ya)/0.026)-1)
where y is the function, x is the independent variable and a is the coefficient i would like to obtain.
Hope there would be someone advising me on the problem i faced as soon as possible.
I apologise for the poor language. Hope someone could help me with it.
Many Thanks!
Best Regards,
June
I hope someone could help me with the current problem i have. Because i need to solve this problem as soon as possible. Have been trying for few days but the problem still there.
In any case where my problem is unclear, please let me know and i'll try to explain your doubts.
Thanks alot!
June, I don't have your data so I can only make some observations. First,
your expected parameter values are of vastly different magnitude. I believe
you will be better off if you scale them, so for example b is on the order
of 1. For example:
ft = fittype('a*((log(x/(1e-13*b)))-((x(1)/x*(x(1)/(1e-13*b)))))')
You can see I have replaced b by 1e-13*b. Now I would expect an estimate of
b close to 1, which is not much different from the magnitude of my expected
result for a. This seemed to help a great deal in a little experiment I
tried using my own generated data.
Second, you have written your equation so that it depends on x(1). That
might work for fitting -- I'm not sure. But if you try to evaluate at a set
of x values later, it will depend on the first x in those evaluation points
rather than the first measured x. Consider replacing x(1) by the value of
the first measured x point.
Third, try to choose good starting values.
> 2) I have a custom equation where the function is describe by y=f(x,y).
> Where the variables are non separable. When I apply the the equation to
> fit a set of data with y=f(x,y), the error indicated that y cannot be part
> of the custom equation. I would like to ask if there is anyone could give
> me an idea how do i input such equation? Following is the equation i would
> like to optimize to a set of data points:
>
> y=1e-13(exp((x-ya)/0.026)-1)
You could invert this to write x as a function of y. Then you could fit that
by swapping the roles of the two variables. All depends on how you want the
error term to fit in. If you want to perform least squares on the
differences between the two sides of the equation as you wrote them, this
transformation wouldn't be appropriate.
Suppose you don't want to transform. It is possible to fit an implicit
equation like this, but I haven't figured out a way to do it with the Curve
Fitting Toolbox. For example, here's a simplified version of your problem
for which I can use fminsearch to estimate the parameter:
% To fit y = exp((x-y)/a) or
% x = y + a*log(y)
y0 = .01 + .1*rand(40,1); % baseline y value
x = y0 + 0.026*log(y0); % find x by inversion
y = y0 + randn(size(y0))/1000; % add error to the observed y
% Define the residual sum of squares
f = @(a) norm(y - exp((x-y)/a))^2;
% Use fminsearch to minimize that
p = fminsearch(f, 0.01)
It should also be possible to use Statistics or Optimization Toolbox
functions to fit this type of model.
-- Tom