how can I fit the following points to equation "f(x) = a + b*exp(-c*x)"
1 view (last 30 days)
Show older comments
Sanskar Agrawal
on 14 Oct 2019
Answered: Star Strider
on 14 Oct 2019
x = 30, 60, 90, 120, 150, 180, 240, 270, 300, 330, 360, 390, 420
y = 333.15, 332.15, 330.65, 330.15, 329.15, 328.15, 327.65, 326.65, 326.15, 325.15, 324.65, 324.15, 323.15, 322.65, 322.15, 321.65
0 Comments
Accepted Answer
Star Strider
on 14 Oct 2019
Try this:
x = [30, 60, 90, 120, 150, 180, 240, 270, 300, 330, 360, 390, 420];
y = [333.15, 332.15, 330.65, 330.15, 329.15, 328.15, 327.65, 326.65, 326.15, 325.15, 324.65, 324.15, 323.15, 322.65, 322.15, 321.6];
yt = y(1:numel(x)); % Truncate ‘y’ To Match Length Of ‘x’
f = @(b,x) b(1) + b(2).*exp(b(3).*x); % Objective Function
[B,fval] = fminsearch(@(b)norm(yt - f(b,x)), [100; 10; -1]); % Estimate Parameters
xe = linspace(min(x), max(x)); % Higher-Resolution ‘x’
figure
plot(x, yt, 'p')
hold on
plot(xe, f(B,xe), '-r')
hold off
grid
legend('Data','Regression Equation')
xl = xlim;
yl = ylim;
text(0.2*diff(xl)+min(xl), 0.1*diff(yl)+min(yl), sprintf('$y(x) = %.1f + %.1f e^{%.6f}$', B), 'Interpreter','latex')
Provide additional elements for ‘x’ to fit all the elements of ‘y’.
0 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!