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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Correct

27Size

Leading solution size is 13.
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

%% assert(isequal(.5, round(1e6*coin_head_match(1))/1e6))

2

Pass

%% assert(isequal(.375, round(1e6*coin_head_match(2))/1e6))

3

Pass

%% assert(isequal(.3125, round(1e6*coin_head_match(3))/1e6))

4

Pass

%% assert(isequal(.273438, round(1e6*coin_head_match(4))/1e6))

5

Pass

%% assert(isequal(.246094, round(1e6*coin_head_match(5))/1e6))

6

Pass

%% assert(isequal(.225586, round(1e6*coin_head_match(6))/1e6))

7

Pass

%% assert(isequal(.139950, round(1e6*coin_head_match(16))/1e6))

8

Pass

%% assert(isequal(.125371, round(1e6*coin_head_match(20))/1e6))

9

Pass

%% assert(isequal(.114567, round(1e6*coin_head_match(24))/1e6))

10

Pass

%% assert(~isequal(1,2))

11

Pass

%% assert(isequal(.099347, round(1e6*coin_head_match(32))/1e6))

12

Pass

%% assert(isequal(.070386, round(1e6*coin_head_match(64))/1e6))

[Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Result may not be exact. Coefficient is greater than 1.000000e+15 and is only accurate to 15 digits] [> In nchoosek at 64 In coin_head_match>@(x)(nchoosek(n,x)*.5^n).^2 at 2 In coin_head_match at 2 In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14]