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

Solution 242129

Submitted on 9 May 2013 by Paul Berglund

Correct

36Size
Leading solution size is 29.
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 3 2];
n=5;
y_correct = [1     4     9    16    25];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     1     4     9    16    25
2
Pass
 
%%
x = [1 4 6];
n=6;
y_correct = [1     5    15    31    53    81];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     1     5    15    31    53    81
3
Pass
 
%%
x = [10 -4 4];
n=7;
y_correct = [10 6 6 10 18 30 46];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
    10     6     6    10    18    30    46
4
Pass
 
%%
x = [100 10 -5];
n=5;
y_correct = [100 110 115 115 110];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
   100   110   115   115   110
5
Pass
 
%%
x = [0 -10 4 -2 6];
n=10;
y_correct = [ 0   -10   -16   -20   -18     0    50   154   340   642];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     0   -10   -16   -20   -18     0    50   154   340   642
6
Pass
 
%%
x = [3 0];
n=4;
y_correct = [3 3 3 3 ];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     3     3     3     3
7
Pass
 
%%
x = [6 1];
n=4;
y_correct = [6 7 8 9];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     6     7     8     9
8
Pass
 
%%
x = [-10 1 -5 2];
n=10;
y_correct = [-10    -9   -13   -20   -28   -35   -39   -38   -30   -13];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
   -10    -9   -13   -20   -28   -35   -39   -38   -30   -13
9
Pass
 
%%
x = [ 1     3    -1    -2     2     1];
n=10;
y_correct = [ 1     4     6     5     1    -3     0    22    81   202];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     1     4     6     5     1    -3     0    22    81   202
10
Pass
 
%%
x = [0 0 0];
n=5;
y_correct = [0 0 0 0 0];
assert(isequal(commondiff2seq(x,n),y_correct))
ans =
     0     0     0     0     0