MATLAB Answers

model for fitting polynomial of degree 3

3 views (last 30 days)
Hi, i want to use 'fitlm' for fitting polynomial of degree 3. Is there some builtin name for the model? For example, for degree 2, matlab used model 'Quadratic'. I tried 'Quartic' but it did not worked.

Accepted Answer

John D'Errico
John D'Errico on 20 Aug 2020
Edited: John D'Errico on 20 Aug 2020
Just read the help.
x = rand(10,1);
>> y = rand(10,1);
>> D = dataset(x,y);
>> fitlm(D,'poly3')
ans =
Linear regression model:
y ~ 1 + x + x^2 + x^3
Estimated Coefficients:
Estimate SE tStat pValue
__________________ _________________ __________________ __________________
(Intercept) 0.883325330921357 0.269610952016709 3.27629617533717 0.0169006334507573
x -0.905689721171103 2.50947007046528 -0.36090875592837 0.73053441711432
x^2 2.97715513265619 5.78699413259576 0.514456221043511 0.625326610386953
x^3 -2.49404374290891 3.78096082734174 -0.659632261956649 0.53397526842927
Number of observations: 10, Error degrees of freedom: 6
Root Mean Squared Error: 0.182
R-squared: 0.222, Adjusted R-Squared: -0.167
F-statistic vs. constant model: 0.57, p-value = 0.655
I could also have written the model as:
fitlm(D,'y ~ 1 + x + x^2 + x^3')
which produces the same result.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!