Polynomial regression: Difference between revisions

Added a solution for MATLAB
No edit summary
(Added a solution for MATLAB)
Line 421:
Y (%. (^/x:@i.@#)) X
1 2 3 0 0 0 0 0 0 0 0</lang>
 
=={{header|MATLAB}}==
Matlab has a built-in function "polyfit(x,y,n)" which performs this task. The arguments x and y are vectors which are parametrized by the index suck that <math>point_{i} = (x_{i},y_{i})</math> and the argument n is the order of the polynomial you want to fit. The output of this function is the coefficients of the polynomial which best fit these x,y value pairs.
 
<lang MATLAB>>> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
>> y = [1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321];
>> polyfit(x,y,2)
 
ans =
 
2.999999999999998 2.000000000000019 0.999999999999956</lang>
 
 
=={{header|Octave}}==
Anonymous user