![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1132400/image.png)
I want to do exponential fitting for power decaying with time
27 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I have this matrix (first cloumn is time while the second column is received power), I want to do exponentially fitting, how can I can do it and how can I find time-decaying constant of the exponential.
x=[
65.10 1.0000e+000
65.90 61.0843e-003
70.30 21.3693e-003
];
0 件のコメント
採用された回答
Image Analyst
2022 年 9 月 21 日
If you have the Statistics and Machine Learning Toolbox you can use fitnlm. See attached full demo. Replace the demo data with your own. However I'll tell you that any fit with only 3 data points will probably be very inaccurate. You should definitely make more measurements.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1132400/image.png)
0 件のコメント
その他の回答 (2 件)
Torsten
2022 年 9 月 21 日
x=[
65.10 1.0000e+000
65.90 61.0843e-003
70.30 21.3693e-003
];
fun = @(p)exp(-p*(x(:,1)-65.1));
fun1 = @(p)fun(p)-x(:,2);
p = lsqnonlin(fun1,0.1)
format long
fun1(p)
hold on
plot(x(:,1),x(:,2))
plot(x(:,1),fun(p))
hold off
0 件のコメント
Cris LaPierre
2022 年 9 月 21 日
The easiest approach is to use the Curve Fitting app inside a live script. This does require having the Curve Fitting Toolbox installed. Once done, you can have the app generate the corresponding code. Here is what that code might look like.
x=[
65.10 1.0000e+000
65.90 61.0843e-003
70.30 21.3693e-003
];
X = x(:,1);
Y = x(:,2);
[xData, yData] = prepareCurveData( X, Y );
% Set up fittype and options.
ft = fittype( 'exp1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [1.19913731842403e+35 -1.24044938669103];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'Y vs. X', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'X', 'Interpreter', 'none' );
ylabel( 'Y', 'Interpreter', 'none' );
grid on
I assume you are intersted in the coefficient b.
fitresult
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!