Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

74Size
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 Suite

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)

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

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

                    
4
Pass
 
%%
x = [1 1]; y = [1 -2]; c = 50;
y_correct = 1;
assert(abs(getTheRightPosition(x,y,c)-y_correct)<1e-10)
[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]
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]
6
Pass
 
%%
x = [1 2]; y = [1 1]; c = 50;
y_correct = NaN;
assert(isequal(isnan(getTheRightPosition(x,y,c)),isnan(y_correct)))

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