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

조회 수: 785(최근 30일)
MCC
MCC 2018년 2월 23일
편집: Fatma Keskin 2020년 12월 27일
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일
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))
  댓글 수: 10
Fatma Keskin
Fatma Keskin 2020년 12월 27일
I applied this to my own data but obtained a linear graph. I also changed the estimated parameters. I am wondering what the problem is actually.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by