MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayCorrect

31Size

Leading solution size is 31.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test

Code Input and Output

1

Pass

%% x = [1 2]; y = [5 6]; c = 5; y_correct = 1; assert(abs(getTheRightPosition(x,y,c)-y_correct)<1e-10)

ans = 1.0000

2

Pass

%% x = [1 -2]; y = [1 -2]; c = 50; y_correct = 50; assert(abs(getTheRightPosition(x,y,c)-y_correct)<1e-10)

ans = 50.0000

3

Pass

%% x = [1 -2]; y = [1 2]; c = 50; y_correct = -146; assert(abs(getTheRightPosition(x,y,c)-y_correct)<1e-10)

ans = -146.0000

4

Pass

%% x = [1 1]; y = [1 -2]; c = 50; y_correct = 1; assert(abs(getTheRightPosition(x,y,c)-y_correct)<1e-10)

ans = 1

5

Pass

%% x = [1 1]; y = [1 1]; c = 50; y_correct = NaN; assert(isequal(isnan(getTheRightPosition(x,y,c)),isnan(y_correct)))

[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.] [> In polyfit at 76 In getTheRightPosition at 2 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] ans = NaN

6

Pass

%% x = [1 2]; y = [1 1]; c = 50; y_correct = NaN; assert(isequal(isnan(getTheRightPosition(x,y,c)),isnan(y_correct)))

[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.] [> In polyfit at 76 In getTheRightPosition at 2 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] ans = NaN

7

Pass

%% x = [1 2]; y = [2 2]; c = 2; y_correct = Inf; assert(isequal(isinf(getTheRightPosition(x,y,c)),isinf(y_correct)))

[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.] [> In polyfit at 76 In getTheRightPosition at 2 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14 In workspacefunc at 7] ans = Inf

1 Comment