Cody

Problem 661. Spot the outlier

Solution 1219560

Submitted on 25 Jun 2017 by Augusto Mazzei
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
pts = [0 1; 0 2; 3 2; 0 3; 0 4 ]; outlier = 3; assert(isequal(spot_the_outlier(pts),outlier))

c = -0.3333 3.0000 P = 3.0000 2.0000 3.0000 3.0000 c = -0.2222 2.6667 P = 2.6667 2.0000 2.6667 2.6667 [Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.] c = -Inf 3.0000 P = NaN NaN NaN NaN outlier = 3

2   Pass
pts = [10 -1;7 0;9.5 0.3;9 1.6;8.5 2.9]; outlier = 2; assert(isequal(spot_the_outlier(pts),outlier))

c = 0.3143 -1.4714 P = 0.7286 1.5143 1.3571 1.2000 c = -2.6000 25.0000 P = -1.0000 0.3000 1.6000 2.9000 outlier = 2

3   Pass
pts = [-0.6 -6;-0.2 0;0 3;-0.8 -9;-2 1;-0.4 -3]; outlier = 5; assert(isequal(spot_the_outlier(pts),outlier))

c = 0.3797 -1.3418 P = -1.4177 -1.3418 -1.6456 -2.1013 -1.4937 c = -0.2817 -3.0141 P = -2.8451 -3.0141 -2.7887 -2.4507 -2.9014 c = -1.8000 -4.8400 P = -3.7600 -4.4800 -3.4000 -1.2400 -4.1200 c = -0.1592 -1.1019 P = -1.0064 -1.0701 -1.1019 -0.7834 -1.0382 c = 15.0000 3.0000 P = -6.0000 0.0000 3.0000 -9.0000 -3.0000 outlier = 5

4   Pass
pts = [2 5;0 4;0 0;4 6;-2 3]; outlier = 3; assert(isequal(spot_the_outlier(pts),outlier))

c = 0.6053 2.9474 P = 2.9474 2.9474 5.3684 1.7368 c = 0.7000 2.8000 P = 4.2000 2.8000 5.6000 1.4000 c = 0.5000 4.0000 P = 5.0000 4.0000 6.0000 3.0000 outlier = 3

5   Pass
pts = [1 0; 0 1; 1 2; 1.5 2.5; 2 3; 3 4 ]; outlier = 1; assert(isequal(spot_the_outlier(pts),outlier))

c = 1.0000 1.0000 P = 1.0000 2.0000 2.5000 3.0000 4.0000 outlier = 1

Suggested Problems

More from this Author50

Community Treasure Hunt

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

Start Hunting!