필터 지우기
필터 지우기

Matlab curve fitter error with exponential form with 2 terms

조회 수: 2 (최근 30일)
Briana Canet
Briana Canet 2023년 11월 11일
댓글: Torsten 2023년 11월 11일
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];

채택된 답변

Matt J
Matt J 2023년 11월 11일
편집: Matt J 2023년 11월 11일
% 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
Briana Canet
Briana Canet 2023년 11월 11일
What is the fit type for a linear curve following y = mx + b
Torsten
Torsten 2023년 11월 11일
% 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)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 11일
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
Torsten
Torsten 2023년 11월 11일
편집: Torsten 2023년 11월 11일
The fitted curve shouldn't be convex - the data are measurements of a utility curve.

댓글을 달려면 로그인하십시오.


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 11일
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

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by