How to do exponential curve fitting like y=a*exp(b*x)+c

285 ビュー (過去 30 日間)
MCC
MCC 2018 年 2 月 23 日
コメント済み: Star Strider 2022 年 11 月 9 日
Hi guys,
I have a set of data x and y, which is given below: x=[10 12.5 15 17.5 20 22.5 25 27.5 30 32.5 35 37.5 40 42.5 45 47.5 50]; y=[62.1 77.3 92.5 104 112.9 121.9 125 129.4 134 138.2 142.3 143.2 144.6 147.2 147.8 149.1 150.9];
I'd like to to have a curve fitting like y=a*exp(b*x)+c. I tried to use cftool box (custom equation). However, it didn't work well. I am wandering if someone could help me with this.
Thanks
  1 件のコメント
Arturo Gonzalez
Arturo Gonzalez 2020 年 9 月 1 日
編集済み: Arturo Gonzalez 2020 年 9 月 1 日
Per this answer, you can do it as follows:
clear all;
clc;
% get data
dx = 0.02;
x = (dx:dx:1.5)';
y = -1 + 5*exp(0.5*x) + 4*exp(-3*x) + 2*exp(-2*x);
% calculate integrals
iy1 = cumtrapz(x, y);
iy2 = cumtrapz(x, iy1);
iy3 = cumtrapz(x, iy2);
% get exponentials lambdas
Y = [iy1, iy2, iy3, x.^3, x.^2, x, ones(size(x))];
A = pinv(Y)*y;
lambdas = eig([A(1), A(2), A(3); 1, 0, 0; 0, 1, 0]);
lambdas
%lambdas =
% -2.9991
% -1.9997
% 0.5000
% get exponentials multipliers
X = [ones(size(x)), exp(lambdas(1)*x), exp(lambdas(2)*x), exp(lambdas(3)*x)];
P = pinv(X)*y;
P
%P =
% -0.9996
% 4.0043
% 1.9955
% 4.9999

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

採用された回答

Star Strider
Star Strider 2018 年 2 月 23 日
Try this:
x=[10 12.5 15 17.5 20 22.5 25 27.5 30 32.5 35 37.5 40 42.5 45 47.5 50];
y=[62.1 77.3 92.5 104 112.9 121.9 125 129.4 134 138.2 142.3 143.2 144.6 147.2 147.8 149.1 150.9];
f = @(b,x) b(1).*exp(b(2).*x)+b(3); % Objective Function
B = fminsearch(@(b) norm(y - f(b,x)), [-200; -1; 100]) % Estimate Parameters
figure
plot(x, y, 'pg')
hold on
plot(x, f(B,x), '-r')
hold off
grid
xlabel('x')
ylabel('f(x)')
text(27, 105, sprintf('f(x) = %.1f\\cdote^{%.3f\\cdotx}%+.1f', B))
  14 件のコメント
Kate Leary
Kate Leary 2022 年 11 月 9 日
Thank you thank you! Is there a way to calculate prediction bounds as well? I know of predint but can't figure out how to use is without having a cfit or sfit object. Again, thank you for your help!
Star Strider
Star Strider 2022 年 11 月 9 日
My pleasure!
They’re actually plotted (as ‘95% CI’, just so narrow that it’s difficult to see them here. the predict function call in my code calculates them:
[yv,yci] = predict(mdl,xv(:));
and they are then plotted in:
hp{3} = plot(xv, yci, ':r', 'DisplayName', '95% CI');
If you have any further questions, please feel free to follow up here.
.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by