Polyfit with other model

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

Respuestas (1)

Bruno Luong
Bruno Luong el 3 de Ag. de 2020
Editada: Bruno Luong el 3 de Ag. de 2020

0 votos

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');

Categorías

Más información sobre Polynomials en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 3 de Ag. de 2020

Editada:

el 3 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by