Attempting to get a line of best fit for a custom function

2 次查看(过去 30 天)
I am trying to get a line of best fit for a custom function. Here is my code and the plot that it produces. The problem is that the line seems to be touching every point, which is not what I want. Any suggestions? Also I understand that I can use the curve fitting app, but I prefer doing this by writing up a code
clc;
x(1,:) = Y1;
x(2,:) = Dmge;
plot(x(1,:),x(2,:),'.');
A= 5500; B=0.19; C=2.3;
goemp_fit1 = @(y)sum((y(1)*exp(-exp(-y(2)*(x(1,:)-y(3))))-x(2,:)).^2);
coeff = fminsearch(goemp_fit1,[A B C]);
A = coeff(1);
B = coeff(2);
C = coeff(3);
x2 = x(1,:);
y2 = A*exp(-exp(-B*(x-C)));
plot(x2,y2,'-m')

采纳的回答

Walter Roberson
Walter Roberson 2018-9-9
x2 = x(1,:);
that is one row and multiple columns
y2 = A*exp(-exp(-B*(x-C)));
that involves all of x, so it involves two rows and multiple columns. Perhaps you should be using
y2 = A*exp(-exp(-B*(x2-C)));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by