Given an equation and data points, find the best fit coefficients of the equation

4 Ansichten (letzte 30 Tage)
I have a set of data points:
x=0:1:5;
y=[1 3 9 27 81 243];
and I need to determine the coefficients of the exponential sum of order one f (x) = which best approximates in the least squares sense the assigned data and the residual corresponding to it.
Shuld I use polyfit? I have no idea
Thank you in advance

Akzeptierte Antwort

Torsten
Torsten am 2 Jan. 2022
Bearbeitet: Torsten am 2 Jan. 2022
x = 0:5;
y = [1 3 9 27 81 243];
A = [ones(6,1),exp(x.')];
b = y.';
a = A\b;
f = @(x) a(1)+a(2)*exp(x);
plot(x,[f(x);y])
"a" gives the coefficients of your equation:
a(1) = a0, a(2) = a1

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by