Cody

Solution 1718037

Submitted on 31 Jan 2019
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   Fail
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 = 3.7417 5.0000 e = struct with fields: R: [2×2 double] df: 4 normr: 2.8087e-15 r2 = 2.5000 1.8708 b = 3.7417 5.0000 r2 = 2.5000 1.8708 e = struct with fields: R: [2×2 double] df: 4 normr: 2.8087e-15

Assertion failed.

2   Fail
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))

Error using polyfit (line 44) X and Y vectors must be the same size. Error in RegressionN (line 2) [b, e, r2] = polyfit(x, y, p) Error in Test2 (line 7) [b,r2,e] = RegressionN(x,y,p)

3   Fail
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 = 0.3492 0.3569 0.2043 -0.5987 e = struct with fields: R: [4×4 double] df: 4 normr: 1.0728 r2 = 6.0000 0.6999 b = 0.3492 0.3569 0.2043 -0.5987 r2 = 6.0000 0.6999 e = struct with fields: R: [4×4 double] df: 4 normr: 1.0728

Assertion failed.