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

2 visualizaciones (últimos 30 días)
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')

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Sept. de 2018
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)));

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by