Logarithmic and exponential curve fitting

6 ビュー (過去 30 日間)
Lotte
Lotte 2011 年 10 月 25 日
回答済み: TED MOSBY 2025 年 6 月 9 日
Hello,
I have two sets of data and I would like to fit a logarithmic function (base 10) to the first dataset and an exponential function (also base 10) to the second dataset. Could you please tell me how to do this? I am unexperienced in curve fitting (details are welcome)...
Thanks

回答 (1 件)

TED MOSBY
TED MOSBY 2025 年 6 月 9 日
Hi,
You can use MATLAB's "fit" and "polyfit" functions to fit the data after preprocessing it. For the logarithmic function you can fit it like below:
% Assuming your datasets are stored in MATLAB arrays
% Here x1 is your independent variable and y1 is your dependent variable
log10_x1 = log10(x1); % transform x-values with log10
coeffs_log = polyfit(log10_x1, y1, 1); % Linear fit on transformed data
% Coefficients
a_log = coeffs_log(1);
b_log = coeffs_log(2);
% Fitted function
y1_fit = a_log * log10(x1) + b_log;
Likewise you can fit for the exponential function:
log10_y2 = log10(y2); % transform y-values with log10
coeffs_exp = polyfit(x2, log10_y2, 1); % Linear fit on transformed data
% Coefficients
b_exp = coeffs_exp(1);
log10_a_exp = coeffs_exp(2);
a_exp = 10^(log10_a_exp);
% Fitted function
y2_fit = a_exp * 10.^(b_exp * x2);
You can then proceed to plot the results to visualize them.
For more information on the fitting functions please refer to the documentation below:
Hope this helps!

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by