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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Try out this test problem first.

Given the variable x as your input, multiply it by two and put the result in y.

Examples:

Input x = 2 Output y is 4

Input x = 17 Output y is 34

**Press the "Solve This Now!" button below to get started...**

16129 correct solutions
3548 incorrect solutions

Last solution submitted on Apr 19, 2015

33 players like this problem

1 Comment

Matthew Caron
on 7 Jan 2015

This was a great starter question.

1 Comment

asdasdasd
on 26 Dec 2014

what is the correct answer??

1 Comment

Divya
on 16 Jan 2014

Is it wrong?

2 Comments

Anand Abhishek Singh
on 24 Sep 2013

how leading solution size is 0?

Clayton
on 11 Nov 2013

Probably hacked something

4 players like this solution

6 Comments

Show
3 older comments

Greg
on 9 Sep 2013

What the heck is freepass?

Ramesh Vukyam
on 23 Oct 2013

Is this a solution ?

J.R.! Menzinger
on 10 Feb 2014

Nice place to test... ;-)

Alison
on 20 May 2014

cute but ridiculous

213
on 28 Jun 2014

why it's 'freepass.please',not other words else?

Alfonso Nieto-Castanon
on 28 Jun 2014

'freepass' is just a (cute but ridiculous) hack (see problem http://www.mathworks.com/matlabcentral/cody/problems/1774-free-passes-for-everyone ). The 'please' part is because we are really polite...

1 player likes this solution

2 Comments

ABHAY SONI
on 7 Dec 2012

can anyone tell me why this is incorrect

Ned Gulley
on 12 Mar 2013

I see two problems. It needs to be a function (as modeled by the template), and the input command hangs and times out when called by a web service.

7 players like this solution

5 Comments

Show
2 older comments

Dirk Engel
on 27 Jun 2012

It works, but it's ugly :-)

Chang Ho
on 6 Aug 2012

Nice! :)

Marlies
on 16 Nov 2012

Never realized that MATLAB sees a defined assignment (y = 2*x) different than no assignment (2*x => assignment to ans).
If anything, I would have guessed the second would be (slightly) more effort.

Zaka
on 23 Mar 2013

does this variable "ans" overrides MATLAB's default "ans"?

David Amor
on 27 Apr 2013

ok, i got there in the end. but it defeats the rules - there is no "y" variable when you change the template to ans = times2(x)...
how do you know what the rules are?!?

1 player likes this solution

1 Comment

Justyna Zander
on 3 Apr 2012

Missing test cases:
assert(isequal(times2(0),0));
assert(isequal(times2(0.1),0.2));
assert(isequal(times2(0.000001),0.000002));
assert(isequal(times2(0.1000000000001),0.2000000000002));
assert(isequal(times2(1.0000000000000000000000000000001),2));
assert(isequal(times2(-0),0));
... and a few others.

1 player likes this solution

2 Comments

Jan Simon
on 26 Jan 2012

The test suite is weak. Please add:
assert(isequal(times2(Inf), Inf))
assert(isequal(times2(NaN), NaN))
assert(isequal(times2([]), []))
assert(isequal(times2(magic(3)), 2*magic(3)))

Jan Simon
on 26 Jan 2012

To focus the power of Matlab, add these tests:
assert(isequal(times2(Inf), Inf)) assert(isequal(times2(NaN), NaN))
assert(isequal(times2([]), [])) assert(isequal(times2(magic(3)), 2*magic(3)))

8 Comments