Attempting to get a line of best fit for a custom function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Naveed Hossain
le 9 Sep 2018
Réponse apportée : Walter Roberson
le 9 Sep 2018
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')
1 commentaire
Réponse acceptée
Walter Roberson
le 9 Sep 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)));
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!