Matlab curve fitter error with exponential form with 2 terms
3 views (last 30 days)
Show older comments
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];
0 Comments
Accepted Answer
Matt J
on 11 Nov 2023
Edited: Matt J
on 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 ])
plot(theFit , x , y)
2 Comments
Torsten
on 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')
plot(theFit , x , y)
More Answers (2)
Sulaymon Eshkabilov
on 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);
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 Comment
Sulaymon Eshkabilov
on 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);
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
0 Comments
See Also
Categories
Find more on Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!