필터 지우기
필터 지우기

curvefitting - sum of exponential function

조회 수: 4 (최근 30일)
Inho Kang
Inho Kang 2018년 3월 28일
답변: Arturo Gonzalez 2020년 9월 8일
I have data from experiment.
I want to find the best-fit curve for this and I expect that the result will be “∑A(k)*exp(-t/lamda(k))” A(k) and lamda(k) are coefficients
Since I don’t have “curvefitting tool”, <1>does it work for such function above?
If not, <2>how can I find the best coefficient with the least calculation time?

답변 (1개)

Arturo Gonzalez
Arturo Gonzalez 2020년 9월 8일
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--');

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!