lsqcurvefit is undefined in MathLab version R2007b

2 ビュー (過去 30 日間)
Lieu-Kim Dang
Lieu-Kim Dang 2022 年 1 月 16 日
コメント済み: Mathieu NOE 2022 年 1 月 17 日
Hello MathLab community,
I have copied follwong code from MathWorks example:
xdata = ...
[0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = ...
[455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
fun = @(x,xdata)x(1)*exp(x(2)*xdata);
x0 = [100,-1];
x = lsqcurvefit(fun,x0,xdata,ydata)
Running this code gives following error:
??? Undefined function or method 'lsqcurvefit' for input arguments of type 'function_handle'.
Error in ==> Fitt_2 at 11
x = lsqcurvefit(fun,x0,xdata,ydata)
What is the problem in the code?
Can anybody help to solve?
I'm working with MathLab version R2007b.
Thank you.
  3 件のコメント
Matt J
Matt J 2022 年 1 月 16 日
Lieu-Kim Dang comment moved here:
Hello Rik,
thank you for your advice. Which toolbox is needed?
Max Heimann
Max Heimann 2022 年 1 月 16 日
編集済み: Max Heimann 2022 年 1 月 16 日
It seems to be part of the optimization toolbox.
https://mathworks.com/help/optim/ug/lsqcurvefit.html

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 1 月 17 日
hello
FYI, you can do basic curve fitting with fminsearch - without the optimization toolbox
clc
clearvars
x = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
y = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
f = @(a,b,x) a.*exp(b.*x);
obj_fun = @(params) norm(f(params(1), params(2),x)-y);
sol = fminsearch(obj_fun, [0,0]);
a = sol(1);
b = sol(2);
xfit = linspace(min(x),max(x),100);
yfit = f(a, b, xfit);
figure;
plot(x, y, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(xfit, yfit, '-');
TE = sprintf('C = %0.2fe^{%0.3ft}',a, b);
text(x(3), y(3)*1.5, TE);
  2 件のコメント
Rik
Rik 2022 年 1 月 17 日
You do need to be aware that fminsearch is more sensitive to local minima than many other fitters in Matlab, or so I've heard.
Mathieu NOE
Mathieu NOE 2022 年 1 月 17 日
For those who want to go beyond fminsearch but still lack the optimization toolbox :

サインインしてコメントする。

その他の回答 (2 件)

Lieu-Kim Dang
Lieu-Kim Dang 2022 年 1 月 17 日
Hello Mathieu,
many thanks for your valuable solution. I will try it out.

Lieu-Kim Dang
Lieu-Kim Dang 2022 年 1 月 17 日
Hello Max,
thank you for your information. I'm contacting MAthLab to get the license for this toolbox.
  1 件のコメント
Rik
Rik 2022 年 1 月 17 日
You posted this comment as an answer. Please use the comment section for comments, as the order of answers can change.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by