Polyfit with other model

1 view (last 30 days)
Adri Ann
Adri Ann on 3 Aug 2020
Edited: Bruno Luong on 3 Aug 2020
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

Answers (1)

Bruno Luong
Bruno Luong on 3 Aug 2020
Edited: Bruno Luong on 3 Aug 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');

Categories

Find more on Polynomials in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!