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 180660

Submitted on 21 Dec 2012 by @bmtran

Correct

40Size
Leading solution size is 33.
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
 
%%
v = [4     2     3     1     1     3     4     5     1     3];
real_r = [1 0 2 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 1 0 0 1; 1 0 0 0 0];
real_u = 1:5;
[r,u] = recurrence(v);
assert(and(isequal(r,real_r), isequal(u,real_u)));

                    
2
Pass
 
%%
v = [1:6,1];
real_r = circshift(eye(6),[0 1]);
real_u = 1:6;
[r,u] = recurrence(v);
assert(and(isequal(r,real_r), isequal(u,real_u)));

                    
3
Pass
 
%%
v = [0 0 0 0 0 0];
real_r = 5;
real_u = 0;
[r,u] = recurrence(v);
assert(and(isequal(r,real_r), isequal(u,real_u)));