Cody

# Problem 44843. Nth Order Polynomial Regression

Solution 1719464

Submitted on 2 Feb 2019 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = 0:5; y = 2*x; p = 1; b_correct = [0;2]; r2_correct = 1; e_correct = [0,0,0,0,0,0]'; [b,r2,e] = RegressionN(x,y,p) assert(nnz(abs(b-b_correct)<1e-12)==p+1) assert(abs(r2-r2_correct)<1e-12) assert(nnz(abs(e-e_correct)<1e-12)==length(x))

b = -0.0000 2.0000 r2 = 1 e = 1.0e-14 * 0.0643 0.0222 0 -0.0888 -0.1776 -0.1776

2   Pass
x = linspace(2,5,12); y = exp(x)'; p = 3; b_correct = [-110.9230,126.8980,-46.7825,6.3467]'; r2_correct = 0.9997; e_correct = [0.8726,-0.6361,-0.8963,-0.4527,0.2214,0.7465,0.8663,0.4864,-0.2751,-1.0207,-0.9863,1.0742]'; [b,r2,e] = RegressionN(x,y,p) assert(nnz(abs(b-b_correct)<1e-4)==p+1) assert(abs(r2-r2_correct)<1e-4) assert(nnz(abs(e-e_correct)<1e-4)==length(x))

b = -110.9230 126.8980 -46.7825 6.3467 r2 = 0.9997 e = 0.8726 -0.6361 -0.8963 -0.4527 0.2214 0.7465 0.8663 0.4864 -0.2751 -1.0207 -0.9863 1.0742

3   Pass
x = linspace(5,7,8); y = [-0.9238 -1.5011 -0.2963 -0.2268 -0.9897 -0.0372 0.1509 1.5324]; p = 3; b_correct = [-196.1472 101.5622 -17.6070 1.0186]'; r2_correct = 0.8063; e_correct = [0.2569 -0.6944 0.3739 0.4017 -0.4505 0.2224 -0.2019 0.0919]'; [b,r2,e] = RegressionN(x,y,p) assert(nnz(abs(b-b_correct)<1e-4)==p+1) assert(abs(r2-r2_correct)<1e-4) assert(nnz(abs(e-e_correct)<1e-4)==length(x))

b = -196.1472 101.5622 -17.6070 1.0186 r2 = 0.8063 e = 0.2569 -0.6944 0.3739 0.4017 -0.4505 0.2224 -0.2019 0.0919