Effacer les filtres
Effacer les filtres

Matlab curve fitter error with exponential form with 2 terms

1 vue (au cours des 30 derniers jours)
Briana Canet
Briana Canet le 11 Nov 2023
Commenté : Torsten le 11 Nov 2023
I am trying to curve fit the following data using the following exponetial form with two terms. I was expecting a concave curve along the points, but it is not producting that.
Please help. I am trying to curve fit the following points.
clc;
clear;
close all;
% Interior Square Footage
sqftL = [1500 1600 1750 1930 2250];
sqftUtilityL = [0 0.25 0.5 0.75 1];

Réponse acceptée

Matt J
Matt J le 11 Nov 2023
Modifié(e) : Matt J le 11 Nov 2023
% Interior Square Footage
x = [1500 1600 1750 1930 2250];
y = [0 0.25 0.5 0.75 1];
theFit=fit(x' , y', 'exp2','Lower',[0 0 -inf -inf],'Upper',[inf 0 0 0 ])
theFit =
General model Exp2: theFit(x) = a*exp(b*x) + c*exp(d*x) Coefficients (with 95% confidence bounds): a = 1.279 (1.066, 1.492) b = 0 (fixed at bound) c = -26.63 (-48.85, -4.412) d = -0.002026 (-0.002675, -0.001378)
plot(theFit , x , y)
  2 commentaires
Briana Canet
Briana Canet le 11 Nov 2023
What is the fit type for a linear curve following y = mx + b
Torsten
Torsten le 11 Nov 2023
% Interior Square Footage
x = [1500 1600 1750 1930 2250];
y = [0 0.25 0.5 0.75 1];
theFit=fit(x' , y', 'poly1')
theFit =
Linear model Poly1: theFit(x) = p1*x + p2 Coefficients (with 95% confidence bounds): p1 = 0.001301 (0.000765, 0.001837) p2 = -1.849 (-2.827, -0.8712)
plot(theFit , x , y)

Connectez-vous pour commenter.

Plus de réponses (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 11 Nov 2023
It does work very well if the initial conditions are given. Here is how it can be attained:
% Interior Square Footage
sqftL = [1500 1600 1750 1930 2250];
sqftUtilityL = [0 0.25 0.5 0.75 1];
FModel = @(b,x)(b(1)*exp(b(2)*x));
b0=[0.1, 0.001]; % Initial guess for b
opts = statset('Display','iter','TolFun',1e-10);
beta = nlinfit(sqftL,sqftUtilityL, FModel,b0, opts);
Norm of Norm of Iteration SSE Gradient Step ----------------------------------------------------------- 0 0.273074 1 0.221476 286.87 0.0226301 2 0.198314 224.135 0.0129788 3 0.180237 186.212 0.00937518 4 0.166374 158.151 0.00708214 5 0.155587 135.318 0.00548545 6 0.147093 116.609 0.00433898 7 0.140339 101.15 0.00349367 8 0.134923 88.2713 0.00285613 9 0.130547 77.4559 0.00236579 10 0.126988 68.305 0.00198214 11 0.124079 60.5079 0.00167742 12 0.121687 53.821 0.00143212 13 0.118845 471.032 0.00770177 14 0.114087 358.822 0.00496453 15 0.109374 18.7422 0.00108585 16 0.10936 0.0926197 7.33474e-05 17 0.10936 0.00929679 2.0398e-05 18 0.10936 0.000358592 3.812e-06 19 0.10936 6.43899e-06 7.23391e-07 20 0.10936 1.44957e-06 1.36534e-07 Iterations terminated: relative change in SSE less than OPTIONS.TolFun
x = linspace(min(sqftL), max(sqftL));
FModel_Vals = (beta(1)*exp(beta(2)*x));
plot(sqftL, sqftUtilityL, 'rd', 'MarkerSize',9, 'MarkerFaceColor','y')
hold on
plot(x, FModel_Vals, 'k', 'LineWidth',2)
legend('Data', 'Fit Model: a*exp(b*x)', 'Location', 'best')
xlabel('sqftL')
ylabel('sqftUtilityL & Fit Model')
grid on
  1 commentaire
Torsten
Torsten le 11 Nov 2023
Modifié(e) : Torsten le 11 Nov 2023
The fitted curve shouldn't be convex - the data are measurements of a utility curve.

Connectez-vous pour commenter.


Sulaymon Eshkabilov
Sulaymon Eshkabilov le 11 Nov 2023
It is better to fit with log fit.
% Interior Square Footage
sqftL = [1500 1600 1750 1930 2250];
sqftUtilityL = [0 0.25 0.5 0.75 1];
FModel = @(b,x)(b(1)*log(x)+b(2));
b0=[1, -1]; % Initial guess for b
opts = statset('Display','iter','TolFun',1e-10);
beta = nlinfit(sqftL,sqftUtilityL, FModel,b0, opts);
Norm of Norm of Iteration SSE Gradient Step ----------------------------------------------------------- 0 179.536 1 0.35434 2.07117 3.24569 2 0.254839 0.156622 2.12012 3 0.0459699 0.0558453 7.45616 4 0.0161053 0.00290256 3.87533 5 0.0160244 1.58261e-05 0.211305 6 0.0160244 8.67478e-09 0.00115783 7 0.0160244 5.22904e-13 6.37516e-07 Iterations terminated: relative change in SSE less than OPTIONS.TolFun
x = linspace(min(sqftL), max(sqftL));
FModel_Vals = (beta(1)*log(x)+beta(2));
plot(sqftL, sqftUtilityL, 'rd', 'MarkerSize',9, 'MarkerFaceColor','y')
hold on
plot(x, FModel_Vals, 'k', 'LineWidth',2)
legend('Data', 'Fit Model: a*log(x)+b', 'Location', 'best')
xlabel('sqftL')
ylabel('sqftUtilityL & Fit Model')
grid on

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!

Translated by