Attempting to get a line of best fit for a custom function
1 回表示 (過去 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')
1 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!