Polyfit with other model
Afficher commentaires plus anciens
Hi,
i am new here,
When i get it right polyfit is for polynomials like this: P(a) = c0 * a^0 + c1 * a^1 + c2 * a^2....
But how to get the coefficients from P(a) = 1 + c1 * a^1 + c^* a^2 .... So that the first value is fixed.
I only find this
Do I just have to subtract from A "1" and from the y too and that's it?
(A and y from the link)
greetings
Réponses (1)
Bruno Luong
le 3 Août 2020
Modifié(e) : Bruno Luong
le 3 Août 2020
Generate test data
x=linspace(0,1,100)
P = [rand(1,3) 1]
y=polyval(P,x) + 0.1*randn(size(x));
Fit polynomial (order n) y=P(x) assuming cst-term = 1.
n = 3;
M = x(:).^(n-1:-1:1);
P = [M\(y(:)-1); 1];
Check
plot(x,y,'.');
hold on
plot(x,polyval(P,x),'r');
Catégories
En savoir plus sur Polynomials dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!