How can I fit an exponential curve?
Show older comments
Below is an example of finding a fit with only one term of exponential term but I dont know how to find the fit of the curve when it has 2 degree of exponential term, i.e.[y = a*e^(bx) + c*e^(dx)]
example for y = a*e^(bx)
phi =[ones(size(xx)),xx];
aa=phi\log(yy);
yfit = exp(phi*aa);
plot(xx, yy, ’ro’, xx, yfit, ’k-’) ;
s=sprintf(’y=%8fexp(%8fx)’,exp(aa(1)),aa(2));

Accepted Answer
More Answers (2)
Image Analyst
on 15 Nov 2018
Arturo Gonzalez
on 8 Sep 2020
Per this answer, you can do it with the following matlab code
clear all;
clc;
% get data
dx = 0.001;
x = (dx:dx:1.5)';
y = -1 + 5*exp(0.5*x) + 4*exp(-3*x) + 2*exp(-2*x);
% calculate n integrals of y and n-1 powers of x
n = 3;
iy = zeros(length(x), n);
xp = zeros(length(x), n+1);
iy(:,1) = cumtrapz(x, y);
xp(:,1) = x;
for ii=2:1:n
iy(:, ii) = cumtrapz(x, iy(:, ii-1));
xp(:, ii) = xp(:, ii-1) .* x;
end
xp(:, n+1) = ones(size(x));
% get exponentials lambdas
Y = [iy, xp];
A = pinv(Y)*y;
Ahat = [A(1:n)'; [eye(n-1), zeros(n-1, 1)]];
lambdas = eig(Ahat);
lambdas
% get exponentials multipliers
X = [ones(size(x)), exp(lambdas'.*x)];
P = pinv(X)*y;
P
% show estimate
y_est = X*P;
figure();
plot(x, y); hold on;
plot(x, y_est, 'r--');
Categories
Find more on Parametric Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
