How can I fit my data to a curve that is only defined implicitly, using Optimization Toolbox 3.0 (R14)?

2 visualizzazioni (ultimi 30 giorni)
I have data that I want to fit to a curve. The equation of the curve is defined implicitly. For example, consider the following equation:
y = A*(x0-x) - B*log(y/y0) + y0;
"x" is an independent variable, "y" is a dependent variable, and "A" and "B" are the parameters to be estimated. "x0" and "y0" are known constants.
The NLINFIT function in the Statistics Toolbox and the LSQCURVEFIT function in the Optimization Toolbox require explicit functions of the form y = f(x).

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Giu 2009
To solve a problem of this type using Optimization Toolbox 3.0 (R14), you must create a function that takes as its input the value of "x", and then numerically computes the value of "y" by calling the FSOLVE function.
For the example:
y = A*(x0-x) - B*log(y/y0) + y0;
Your function could resemble the following:
function yout = myImplicitF(x, AB)
x0 = 0.01;
y0 = 0.01;
A=AB(1);
B=AB(2);
yout = zeros(size(x));
opt = optimset('display','off');
for i=1:length(x)
yout(i) = fsolve(@(y) x(i)- (x0-(y+B*log(y/y0)+y0)/A), .1, opt);
end
The FOR loop is used to allow the function to handle vector inputs for "x". For more information about FSOLVE, type the following at the MATLAB command prompt:
doc fsolve
This function can now be treated as an explicit function of "x". For example, it can be plotted as follows:
ezplot(@(x)myImplicitF(x,[1 1]),[-5 1])
The above statement plots the curve over the range [-5, 1], for "A" and "B" parameters equal to 1.
Suppose you have some measured data, for example:
x = -5:.1:1;
y = myImplicitF(x,[1 1]) + randn(size(x))/100;
The function can be used in curve fitting functions such as LSQCURVEFIT as follows:
lsqcurvefit(@(params, xdata) myImplicitF(xdata,params),[0.1 0.1], x, y)

Più risposte (0)

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by