Fitting implicit function with data

11 Ansichten (letzte 30 Tage)
Mohsen
Mohsen am 7 Apr. 2016
Bearbeitet: Tien Tran am 23 Apr. 2016
Dear all
I want to fit an implicit function with data I have. The function is in terms of X and Y(2 variables) and has 8 constants (x(1)..x(8)) to be found.
f=x(1).*(abs(((x(2).*(X-x(3)))+x(4).*(Y-x(5))))).^(x(6))+x(7).*(abs((X-x(3)-(Y-x(5))))).^(x(6))-x(8).^(x(6));
and my data are:
X = [0 0.41 1.2 2.01 3.5 5 7.1 10.1 12.06 14.2 17.1 17.4 17.9 17.1 14.2 10.1 7.1 5 3.5 2.01 0 -0.8 -3.5 -5.4 -9.5 -12.1 -15.5 -18.5 -22.3 -25.5 -26.7 -27.3 -26.7 -22.5 -18.8 -15.5 -12.1 -9.5 -5.4 -1.7 0];
Y = [17.9 17.7 17.5 18.3 17.87 17.48 16.74 16.7 15.8 15.3 9.02 8.6 0 -4.6 -13.8 -24.1 -26.9 -26.7 -26.5 -26.2 -27.3 -27.9 -26.9 -25.2 -25.1 -22.8 -20.2 -20.1 -10.6 -4.6 -0.9 0 4 8 10.5 11.3 13.8 16.2 17 17.6 17.9];
Can anyone help me to find the constants?
  1 Kommentar
Mohsen
Mohsen am 18 Apr. 2016
Bearbeitet: Walter Roberson am 22 Apr. 2016
I did as follows but needs to be more accurate, How can I pass it through specific points?
function obj= fit_simp(x,X,Y)
X = [0 0.41 1.2 2.01 3.5 5 7.1 10.1 12.06 14.2 17.4 17.9 17.1 14.2 10.1 7.1 5 3.5 2.01 0 -0.8 -3.5 -5.4 -9.5 -12.1 -15.5 -18.5 -22.3 -25.5 -26.7 -27.3 -26.7 -22.5 -18.8 -15.5 -12.1 -9.5 -5.4 -1.7 0];
Y = [17.9 17.7 17.5 18.3 17.87 17.48 16.74 16 15 13.5 8.6 0 -4.6 -13.8 -24.1 -26.9 -26.7 -26.5 -26.2 -27.3 -27.5 -26.7 -26 -25.1 -22.8 -20.2 -17 -10.6 -4.6 -0.9 0 4 8 10.5 11.3 13.8 16.2 17 17.6 17.9];
obj = @(x) x(1).*(abs(((x(2).*(X-x(3)))+x(4).*(Y-x(5))))).^(x(6))+x(7).*(abs((X-x(3)-(Y-x(5))))).^(x(6))-x(8).^(x(6));
x0=[0.001 0.1880 -1.44 0.108 -4 9.984 2.9064e-10 2.1175];
options = optimset('Display','iter','TolFun',1e-8)
[x,resnorm,residual,exitflag,output]=lsqnonlin(obj,x0,[-1],[13],options)
obj_new= @(X,Y) x(1).*(abs(((x(2).*(X-x(3)))+x(4).*(Y-x(5))))).^(x(6))+x(7).*(abs((X-x(3)-(Y-x(5))))).^(x(6))-x(8).^(x(6))
scatter(X,Y)
hold on
ezplot(obj_new,[-30,30,-30,30])

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 19 Apr. 2016
Sorry, but it seems a foolish goal to fit that curve with your function. There are far easier ways to accomplish a curve fit.
Some basic rules of curve fitting:
- If you are using a complex model that was suggested to you by a friend/colleague/boss/etc because it was able to fit their data, or they know of someone who used that model, then you are probably using the wrong model. Consider a spline instead.
- If you have no physical reasons for having chosen the model you are using, EXCEPT that it MIGHT fit IF you throw in enough terms, then you are probably using the wrong model. Consider a spline instead.
- If you are using a complicated model where the parameters have no meaning to you in context, so the resulting nonlinear fit does not converge (possibly) because you cannot guess good starting values, then you are using the wrong model. Consider a spline instead.
Were it my choice, I would just convert to polar coordinates, then fit r(theta) using a tool like a least squares spline model, designed to be a periodic function.
theta = atan2(Y,X);
[thetas,tags] = sort(theta);
r = sqrt(X.^2 + Y.^2);
rs = r(tags);
For example, using my SLM toolbox,I might try this:
slm = slmengine(thetas,rs,'plot','on','endconditions','periodic','knots',15);
thetahat = linspace(-pi,pi,200);
rhat = slmeval(thetahat,slm);
xhat = rhat.*cos(thetahat);
yhat = rhat.*sin(thetahat);
plot(X,Y,'-o',xhat,yhat,'r:')
grid on
  3 Kommentare
John D'Errico
John D'Errico am 22 Apr. 2016
So then fit the model. Wanting it to be more accurate is a waste of time though. The model will be as accurate as it is. If it is not sufficiently accurate, then the model is not a good approximation to the system that produced that data, or you need to get better data. In some cases, you may need to get better starting values.
Forcing the model to pass through specific points (which will take a fair amount of effort here) will just make the model fit worse overall, not better.
Tien Tran
Tien Tran am 23 Apr. 2016
Bearbeitet: Tien Tran am 23 Apr. 2016
Hi John
How to get constants and the function of spline?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by