
Non- Linear curve fitting
3 ビュー (過去 30 日間)
古いコメントを表示
I have a set of data and I need to fit it to the curve F(x,xdata) and then find the values of five unknown coefficients .
a,b,c,d and e are the five coefficients which are replaced by x(0) , x(1) , x(2), x(3), x(4) and x(5) in the code below.
Running this code produces an error message. But when I removed "xdata" which was originally multiplied to the sqaured expression in the later part of the function, I got an output containing the values of the coefficients I needed.
How do i get an ouput while not having to remove "xdata" from the later part of the function?
clc;
Data = ...
[-0.02 2000
0 1650
0.03 1300
0.06 1050
0.09 880
0.12 700
0.15 550
0.18 400
0.21 240
0.24 120
0.27 0 ];
k = Data(:,1);
y = Data(:,2);
F = @(x,xdata)6*(x(1)*exp(-xdata*x(2))-x(3))*(2*(1-xdata*(x(4)*exp(-100000)-x(5)))^2-1);
plot(k,y,'r');
x0 = [1 1 1 1 1];
[x] = lsqcurvefit(F,x0,k,y)
0 件のコメント
採用された回答
Star Strider
2020 年 10 月 11 日
It is necessary to vectorise every multiplication, division,. and exponentiation in an objective function.
With those changes:
F = @(x,xdata)6*(x(1)*exp(-xdata*x(2))-x(3)).*(2*(1-xdata*(x(4)*exp(-100000)-x(5))).^2-1);
and:
figure
plot(k,y,'xr')
hold on
plot(k, F(x,k), '-b')
hold off
grid
xlabel('k')
ylabel('y')
legend('Data', 'F')
produces:

.
3 件のコメント
Star Strider
2020 年 10 月 11 日
As always, my pleasure!
For relatively long expressions, it is sometimes easier to copy the function expression as a character array and use the vectorize function on it. You can then copy that result expression to the original function (obviously without the quotes), and run it. (The documentation says that vectorize is ‘not recommended’ however I have no idea what the reason is, since it is quite useful. I brought this up with MathWorks a few months ago who were as mystified as I was about the designation, however it still exists.)
Alex Sha
2020 年 10 月 29 日
編集済み: Alex Sha
2020 年 10 月 29 日
Hello, Lomalsvi, the part of your fiting equation, "(x4*exp(-100000)-x5)", is really meanless, could be replaced simply by "x(4)", so your equation become: "6*(x(1)*exp(-xdata*x(2))-x(3)).*(2*(1-xdata*x(4)).^2-1);", the result should be same.
その他の回答 (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!