Logarithmic and exponential curve fitting
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
TED MOSBY
le 9 Juin 2025
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!
0 commentaires
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!