Cody

Solution 1719078

Submitted on 1 Feb 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 = 2.0000 -0.0000 r2 = struct with fields: R: [2×2 double] df: 4 normr: 2.7500e-15 e = 1.0e-14 * 0.0643 0.0222 0 -0.0888 -0.1776 -0.1776

Undefined function 'minus' for input arguments of type 'struct'. Error in Test1 (line 9) assert(abs(r2-r2_correct)<1e-12)

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,S] = 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 = 1.0186 -17.6070 101.5622 -196.1472 r2 = struct with fields: R: [4×4 double] df: 4 normr: 1.0728 e = 0.2569 -0.6944 0.3739 0.4017 -0.4505 0.2224 -0.2019 0.0919

Undefined function 'minus' for input arguments of type 'struct'. Error in Test3 (line 9) assert(abs(r2-r2_correct)<1e-4)