Cody

# Problem 8057. (Linear) Recurrence Equations - Generalised Fibonacci-like sequences

Solution 2032546

Submitted on 23 Nov 2019 by Hung Trinh
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
Init = [1,1]; Rules = [1,1]; N = 1:10; values_correct = [1 1 2 3 5 8 13 21 34 55]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 1 a = 1 a = 2 f = 1 1 2 a = 0 a = 1 a = 3 f = 1 1 2 3 a = 0 a = 2 a = 5 f = 1 1 2 3 5 a = 0 a = 3 a = 8 f = 1 1 2 3 5 8 a = 0 a = 5 a = 13 f = 1 1 2 3 5 8 13 a = 0 a = 8 a = 21 f = 1 1 2 3 5 8 13 21 a = 0 a = 13 a = 34 f = 1 1 2 3 5 8 13 21 34 a = 0 a = 21 a = 55 f = 1 1 2 3 5 8 13 21 34 55 a = 0 values = 1 1 2 3 5 8 13 21 34 55

2   Pass
Init = [2,3]; Rules = [1,1]; N = 1:10; values_correct = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 2 3 a = 2 a = 5 f = 2 3 5 a = 0 a = 3 a = 8 f = 2 3 5 8 a = 0 a = 5 a = 13 f = 2 3 5 8 13 a = 0 a = 8 a = 21 f = 2 3 5 8 13 21 a = 0 a = 13 a = 34 f = 2 3 5 8 13 21 34 a = 0 a = 21 a = 55 f = 2 3 5 8 13 21 34 55 a = 0 a = 34 a = 89 f = 2 3 5 8 13 21 34 55 89 a = 0 a = 55 a = 144 f = 2 3 5 8 13 21 34 55 89 144 a = 0 values = 2 3 5 8 13 21 34 55 89 144

3   Pass
Init = [1,1]; Rules = [1,1]; N = -5:5; values_correct = [5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5]; values_accepted = [nan, nan, nan, nan, nan, nan, 1, 1, 2, 3, 5]; values = recurrence_seq(N, Init, Rules); assert(isequal(values,values_correct)||isequaln(values,values_accepted))

t1 = 1 2 3 4 5 t2 = -5 -4 -3 -2 -1 0 t2 = NaN NaN NaN NaN NaN NaN a = 0 f = 1 1 a = 1 a = 2 f = 1 1 2 a = 0 a = 1 a = 3 f = 1 1 2 3 a = 0 a = 2 a = 5 f = 1 1 2 3 5 a = 0 values = NaN NaN NaN NaN NaN NaN 1 1 2 3 5

4   Pass
Init = [1,3]; Rules = [1,1]; N = 1:10; values_correct = [1, 3, 4, 7, 11, 18, 29, 47, 76, 123]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 3 a = 1 a = 4 f = 1 3 4 a = 0 a = 3 a = 7 f = 1 3 4 7 a = 0 a = 4 a = 11 f = 1 3 4 7 11 a = 0 a = 7 a = 18 f = 1 3 4 7 11 18 a = 0 a = 11 a = 29 f = 1 3 4 7 11 18 29 a = 0 a = 18 a = 47 f = 1 3 4 7 11 18 29 47 a = 0 a = 29 a = 76 f = 1 3 4 7 11 18 29 47 76 a = 0 a = 47 a = 123 f = 1 3 4 7 11 18 29 47 76 123 a = 0 values = 1 3 4 7 11 18 29 47 76 123

5   Pass
Init = [1, 1, 1]; Rules = [1, 1, 0]; N = 4:21; values_correct = [2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 1 1 a = 1 a = 2 a = 2 f = 1 1 1 2 a = 0 a = 1 a = 2 a = 2 f = 1 1 1 2 2 a = 0 a = 1 a = 3 a = 3 f = 1 1 1 2 2 3 a = 0 a = 2 a = 4 a = 4 f = 1 1 1 2 2 3 4 a = 0 a = 2 a = 5 a = 5 f = 1 1 1 2 2 3 4 5 a = 0 a = 3 a = 7 a = 7 f = 1 1 1 2 2 3 4 5 7 a = 0 a = 4 a = 9 a = 9 f = 1 1 1 2 2 3 4 5 7 9 a = 0 a = 5 a = 12 a = 12 f = 1 1 1 2 2 3 4 5 7 9 12 a = 0 a = 7 a = 16 a = 16 f = 1 1 1 2 2 3 4 5 7 9 12 16 a = 0 a = 9 a = 21 a = 21 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 a = 0 a = 12 a = 28 a = 28 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 a = 0 a = 16 a = 37 a = 37 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 a = 0 a = 21 a = 49 a = 49 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 a = 0 a = 28 a = 65 a = 65 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 a = 0 a = 37 a = 86 a = 86 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 a = 0 a = 49 a = 114 a = 114 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 a = 0 a = 65 a = 151 a = 151 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 a = 0 a = 86 a = 200 a = 200 f = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 a = 0 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200

6   Pass
Init = [0, 1]; Rules = [1, 2]; N = 4:3:19; values_correct = [5, 70, 985, 13860, 195025, 2744210]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 4 7 10 13 16 19 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 0 1 a = 0 a = 2 f = 0 1 2 a = 0 a = 1 a = 5 f = 0 1 2 5 a = 0 a = 2 a = 12 f = 0 1 2 5 12 a = 0 a = 5 a = 29 f = 0 1 2 5 12 29 a = 0 a = 12 a = 70 f = 0 1 2 5 12 29 70 a = 0 a = 29 a = 169 f = 0 1 2 5 12 29 70 169 a = 0 a = 70 a = 408 f = 0 1 2 5 12 29 70 169 408 a = 0 a = 169 a = 985 f = 0 1 2 5 12 29 70 169 408 985 a = 0 a = 408 a = 2378 f = 0 1 2 5 12 29 70 169 408 985 2378 a = 0 a = 985 a = 5741 f = 0 1 2 5 12 29 70 169 408 985 2378 5741 a = 0 a = 2378 a = 13860 f = 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 a = 0 a = 5741 a = 33461 f = 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 a = 0 a = 13860 a = 80782 f = 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 80782 a = 0 a = 33461 a = 195025 f = Columns 1 through 15 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 80782 Column 16 195025 a = 0 a = 80782 a = 470832 f = Columns 1 through 15 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 80782 Columns 16 through 17 195025 470832 a = 0 a = 195025 a = 1136689 f = Columns 1 through 15 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 80782 Columns 16 through 18 195025 470832 1136689 a = 0 a = 470832 a = 2744210 f = Columns 1 through 15 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 80782 Columns 16 through 19 195025 470832 1136689 2744210 a = 0 values = 5 70 985 13860 195025 2744210

7   Pass
Init = [3-2, 9-4]; Rules = [-6 5]; N = 1:10; values_correct = [1, 5, 19, 65, 211, 665, 2059, 6305, 19171, 58025]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 5 a = -6 a = 19 f = 1 5 19 a = 0 a = -30 a = 65 f = 1 5 19 65 a = 0 a = -114 a = 211 f = 1 5 19 65 211 a = 0 a = -390 a = 665 f = 1 5 19 65 211 665 a = 0 a = -1266 a = 2059 f = 1 5 19 65 211 665 2059 a = 0 a = -3990 a = 6305 f = 1 5 19 65 211 665 2059 6305 a = 0 a = -12354 a = 19171 f = 1 5 19 65 211 665 2059 6305 19171 a = 0 a = -37830 a = 58025 f = 1 5 19 65 211 665 2059 6305 19171 58025 a = 0 values = 1 5 19 65 211 665 2059 6305 19171 58025

8   Pass
Init = [3, 0, 2]; Rules = [1, 1, 0]; N = [28:38, 10:-1:1]; values_correct = [1983, 2627, 3480, 4610, 6107, 8090, 10717, 14197, 18807, 24914, 33004, 12, 10, 7, 5, 5, 2, 3, 2, 0, 3]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 28 29 30 31 32 33 34 35 36 37 38 10 9 8 7 6 5 4 3 2 1 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 3 0 2 a = 3 a = 3 a = 3 f = 3 0 2 3 a = 0 a = 0 a = 2 a = 2 f = 3 0 2 3 2 a = 0 a = 2 a = 5 a = 5 f = 3 0 2 3 2 5 a = 0 a = 3 a = 5 a = 5 f = 3 0 2 3 2 5 5 a = 0 a = 2 a = 7 a = 7 f = 3 0 2 3 2 5 5 7 a = 0 a = 5 a = 10 a = 10 f = 3 0 2 3 2 5 5 7 10 a = 0 a = 5 a = 12 a = 12 f = 3 0 2 3 2 5 5 7 10 12 a = 0 a = 7 a = 17 a = 17 f = 3 0 2 3 2 5 5 7 10 12 17 a = 0 a = 10 a = 22 a = 22 f = 3 0 2 3 2 5 5 7 10 12 17 22 a = 0 a = 12 a = 29 a = 29 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 a = 0 a = 17 a = 39 a = 39 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 a = 0 a = 22 a = 51 a = 51 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 a = 0 a = 29 a = 68 a = 68 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 a = 0 a = 39 a = 90 a = 90 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 a = 0 a = 51 a = 119 a = 119 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 a = 0 a = 68 a = 158 a = 158 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 a = 0 a = 90 a = 209 a = 209 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 a = 0 a = 119 a = 277 a = 277 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 a = 0 a = 158 a = 367 a = 367 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 a = 0 a = 209 a = 486 a = 486 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 a = 0 a = 277 a = 644 a = 644 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 644 a = 0 a = 367 a = 853 a = 853 f = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 644 853 a = 0 a = 486 a = 1130 a = 1130 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 26 68 90 119 158 209 277 367 486 644 853 1130 a = 0 a = 644 a = 1497 a = 1497 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 27 68 90 119 158 209 277 367 486 644 853 1130 1497 a = 0 a = 853 a = 1983 a = 1983 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 28 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 a = 0 a = 1130 a = 2627 a = 2627 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 29 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 a = 0 a = 1497 a = 3480 a = 3480 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 a = 0 a = 1983 a = 4610 a = 4610 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Column 31 4610 a = 0 a = 2627 a = 6107 a = 6107 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 32 4610 6107 a = 0 a = 3480 a = 8090 a = 8090 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 33 4610 6107 8090 a = 0 a = 4610 a = 10717 a = 10717 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 34 4610 6107 8090 10717 a = 0 a = 6107 a = 14197 a = 14197 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 35 4610 6107 8090 10717 14197 a = 0 a = 8090 a = 18807 a = 18807 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 36 4610 6107 8090 10717 14197 18807 a = 0 a = 10717 a = 24914 a = 24914 f = Columns 1 through 15 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Columns 16 through 30 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 2627 3480 Columns 31 through 37 4610 6107 8090 10717 14197 18807 24914 a = 0 a = 14197 a = 33004 a = 33004 f = Columns 1 through 15 3 0 2 ...

9   Pass
Init = [3, 0, 2]; % Perrin init Rules = [1, 1, 1]; % Tribonacci rules N = [1:15]; values_correct = [3, 0, 2, 5, 7, 14, 26, 47, 87, 160, 294, 541, 995, 1830, 3366]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 3 0 2 a = 3 a = 3 a = 5 f = 3 0 2 5 a = 0 a = 0 a = 2 a = 7 f = 3 0 2 5 7 a = 0 a = 2 a = 7 a = 14 f = 3 0 2 5 7 14 a = 0 a = 5 a = 12 a = 26 f = 3 0 2 5 7 14 26 a = 0 a = 7 a = 21 a = 47 f = 3 0 2 5 7 14 26 47 a = 0 a = 14 a = 40 a = 87 f = 3 0 2 5 7 14 26 47 87 a = 0 a = 26 a = 73 a = 160 f = 3 0 2 5 7 14 26 47 87 160 a = 0 a = 47 a = 134 a = 294 f = 3 0 2 5 7 14 26 47 87 160 294 a = 0 a = 87 a = 247 a = 541 f = 3 0 2 5 7 14 26 47 87 160 294 541 a = 0 a = 160 a = 454 a = 995 f = 3 0 2 5 7 14 26 47 87 160 294 541 995 a = 0 a = 294 a = 835 a = 1830 f = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 a = 0 a = 541 a = 1536 a = 3366 f = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 3366 a = 0 values = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 3366

10   Pass
Init = [0, 0, 1]; Rules = [1, 1, 1]; N = [1:23]; values_correct = [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 0 0 1 a = 0 a = 0 a = 1 f = 0 0 1 1 a = 0 a = 0 a = 1 a = 2 f = 0 0 1 1 2 a = 0 a = 1 a = 2 a = 4 f = 0 0 1 1 2 4 a = 0 a = 1 a = 3 a = 7 f = 0 0 1 1 2 4 7 a = 0 a = 2 a = 6 a = 13 f = 0 0 1 1 2 4 7 13 a = 0 a = 4 a = 11 a = 24 f = 0 0 1 1 2 4 7 13 24 a = 0 a = 7 a = 20 a = 44 f = 0 0 1 1 2 4 7 13 24 44 a = 0 a = 13 a = 37 a = 81 f = 0 0 1 1 2 4 7 13 24 44 81 a = 0 a = 24 a = 68 a = 149 f = 0 0 1 1 2 4 7 13 24 44 81 149 a = 0 a = 44 a = 125 a = 274 f = 0 0 1 1 2 4 7 13 24 44 81 149 274 a = 0 a = 81 a = 230 a = 504 f = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 a = 0 a = 149 a = 423 a = 927 f = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 a = 0 a = 274 a = 778 a = 1705 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Column 16 1705 a = 0 a = 504 a = 1431 a = 3136 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 17 1705 3136 a = 0 a = 927 a = 2632 a = 5768 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 18 1705 3136 5768 a = 0 a = 1705 a = 4841 a = 10609 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 19 1705 3136 5768 10609 a = 0 a = 3136 a = 8904 a = 19513 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 20 1705 3136 5768 10609 19513 a = 0 a = 5768 a = 16377 a = 35890 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 21 1705 3136 5768 10609 19513 35890 a = 0 a = 10609 a = 30122 a = 66012 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 22 1705 3136 5768 10609 19513 35890 66012 a = 0 a = 19513 a = 55403 a = 121415 f = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 23 1705 3136 5768 10609 19513 35890 66012 121415 a = 0 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 23 1705 3136 5768 10609 19513 35890 66012 121415

11   Pass
Init = [0, 0, 0, 1]; Rules = [1, 1, 1, 1]; N = [20:23]; values_correct = [20569, 39648, 76424, 147312]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 20 21 22 23 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 0 0 0 1 a = 0 a = 0 a = 0 a = 1 f = 0 0 0 1 1 a = 0 a = 0 a = 0 a = 1 a = 2 f = 0 0 0 1 1 2 a = 0 a = 0 a = 1 a = 2 a = 4 f = 0 0 0 1 1 2 4 a = 0 a = 1 a = 2 a = 4 a = 8 f = 0 0 0 1 1 2 4 8 a = 0 a = 1 a = 3 a = 7 a = 15 f = 0 0 0 1 1 2 4 8 15 a = 0 a = 2 a = 6 a = 14 a = 29 f = 0 0 0 1 1 2 4 8 15 29 a = 0 a = 4 a = 12 a = 27 a = 56 f = 0 0 0 1 1 2 4 8 15 29 56 a = 0 a = 8 a = 23 a = 52 a = 108 f = 0 0 0 1 1 2 4 8 15 29 56 108 a = 0 a = 15 a = 44 a = 100 a = 208 f = 0 0 0 1 1 2 4 8 15 29 56 108 208 a = 0 a = 29 a = 85 a = 193 a = 401 f = 0 0 0 1 1 2 4 8 15 29 56 108 208 401 a = 0 a = 56 a = 164 a = 372 a = 773 f = 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 a = 0 a = 108 a = 316 a = 717 a = 1490 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Column 16 1490 a = 0 a = 208 a = 609 a = 1382 a = 2872 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 17 1490 2872 a = 0 a = 401 a = 1174 a = 2664 a = 5536 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 18 1490 2872 5536 a = 0 a = 773 a = 2263 a = 5135 a = 10671 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 19 1490 2872 5536 10671 a = 0 a = 1490 a = 4362 a = 9898 a = 20569 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 20 1490 2872 5536 10671 20569 a = 0 a = 2872 a = 8408 a = 19079 a = 39648 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 21 1490 2872 5536 10671 20569 39648 a = 0 a = 5536 a = 16207 a = 36776 a = 76424 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 22 1490 2872 5536 10671 20569 39648 76424 a = 0 a = 10671 a = 31240 a = 70888 a = 147312 f = Columns 1 through 15 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Columns 16 through 23 1490 2872 5536 10671 20569 39648 76424 147312 a = 0 values = 20569 39648 76424 147312

12   Pass
Init = [0, 0, 0, 0, 0, 0, 1]; Rules = [1, 1, 1, 1, 1, 1, 1]; N = [7:15, 19]; values_correct = [1, 1, 2, 4, 8, 16, 32, 64, 127, 2000]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 7 8 9 10 11 12 13 14 15 19 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 0 0 0 0 0 0 1 a = 0 a = 0 a = 0 a = 0 a = 0 a = 0 a = 1 f = 0 0 0 0 0 0 1 1 a = 0 a = 0 a = 0 a = 0 a = 0 a = 0 a = 1 a = 2 f = 0 0 0 0 0 0 1 1 2 a = 0 a = 0 a = 0 a = 0 a = 0 a = 1 a = 2 a = 4 f = 0 0 0 0 0 0 1 1 2 4 a = 0 a = 0 a = 0 a = 0 a = 1 a = 2 a = 4 a = 8 f = 0 0 0 0 0 0 1 1 2 4 8 a = 0 a = 0 a = 0 a = 1 a = 2 a = 4 a = 8 a = 16 f = 0 0 0 0 0 0 1 1 2 4 8 16 a = 0 a = 0 a = 1 a = 2 a = 4 a = 8 a = 16 a = 32 f = 0 0 0 0 0 0 1 1 2 4 8 16 32 a = 0 a = 1 a = 2 a = 4 a = 8 a = 16 a = 32 a = 64 f = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 a = 0 a = 1 a = 3 a = 7 a = 15 a = 31 a = 63 a = 127 f = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 a = 0 a = 2 a = 6 a = 14 a = 30 a = 62 a = 126 a = 253 f = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 253 a = 0 a = 4 a = 12 a = 28 a = 60 a = 124 a = 251 a = 504 f = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 253 504 a = 0 a = 8 a = 24 a = 56 a = 120 a = 247 a = 500 a = 1004 f = Columns 1 through 15 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 Columns 16 through 18 253 504 1004 a = 0 a = 16 a = 48 a = 112 a = 239 a = 492 a = 996 a = 2000 f = Columns 1 through 15 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 Columns 16 through 19 253 504 1004 2000 a = 0 values = 1 1 2 4 8 16 32 64 127 2000

13   Pass
Init = [1, -1]; Rules = [1, -1]; N = 1:10; values_correct = [1, -1, 2, -3, 5, -8, 13, -21, 34, -55]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 -1 a = 1 a = 2 f = 1 -1 2 a = 0 a = -1 a = -3 f = 1 -1 2 -3 a = 0 a = 2 a = 5 f = 1 -1 2 -3 5 a = 0 a = -3 a = -8 f = 1 -1 2 -3 5 -8 a = 0 a = 5 a = 13 f = 1 -1 2 -3 5 -8 13 a = 0 a = -8 a = -21 f = 1 -1 2 -3 5 -8 13 -21 a = 0 a = 13 a = 34 f = 1 -1 2 -3 5 -8 13 -21 34 a = 0 a = -21 a = -55 f = 1 -1 2 -3 5 -8 13 -21 34 -55 a = 0 values = 1 -1 2 -3 5 -8 13 -21 34 -55

14   Pass
Init = [1, -1]; Rules = [-1, 1]; N = 1:10; values_correct = [1, -1, -2, -1, 1, 2, 1, -1, -2, -1]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 -1 a = -1 a = -2 f = 1 -1 -2 a = 0 a = 1 a = -1 f = 1 -1 -2 -1 a = 0 a = 2 a = 1 f = 1 -1 -2 -1 1 a = 0 a = 1 a = 2 f = 1 -1 -2 -1 1 2 a = 0 a = -1 a = 1 f = 1 -1 -2 -1 1 2 1 a = 0 a = -2 a = -1 f = 1 -1 -2 -1 1 2 1 -1 a = 0 a = -1 a = -2 f = 1 -1 -2 -1 1 2 1 -1 -2 a = 0 a = 1 a = -1 f = 1 -1 -2 -1 1 2 1 -1 -2 -1 a = 0 values = 1 -1 -2 -1 1 2 1 -1 -2 -1

15   Pass
Init = [1, -1]; Rules = [1, 1]; N = 1:10; values_correct = [1, -1, 0, -1, -1, -2, -3, -5, -8, -13]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 -1 a = 1 a = 0 f = 1 -1 0 a = 0 a = -1 a = -1 f = 1 -1 0 -1 a = 0 a = 0 a = -1 f = 1 -1 0 -1 -1 a = 0 a = -1 a = -2 f = 1 -1 0 -1 -1 -2 a = 0 a = -1 a = -3 f = 1 -1 0 -1 -1 -2 -3 a = 0 a = -2 a = -5 f = 1 -1 0 -1 -1 -2 -3 -5 a = 0 a = -3 a = -8 f = 1 -1 0 -1 -1 -2 -3 -5 -8 a = 0 a = -5 a = -13 f = 1 -1 0 -1 -1 -2 -3 -5 -8 -13 a = 0 values = 1 -1 0 -1 -1 -2 -3 -5 -8 -13

16   Pass
Init = [1, 1]; Rules = [2, -1]; N = 1:10; values_correct = ones(1,10); assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 1 a = 2 a = 1 f = 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 1 1 1 1 a = 0 a = 2 a = 1 f = 1 1 1 1 1 1 1 1 1 1 a = 0 values = 1 1 1 1 1 1 1 1 1 1

17   Pass
Init = [1, 2]; Rules = [2, -1]; N = 1:10; values_correct = [1, 2, 0, 4, -4, 12, -20, 44, -84, 172]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 2 a = 2 a = 0 f = 1 2 0 a = 0 a = 4 a = 4 f = 1 2 0 4 a = 0 a = 0 a = -4 f = 1 2 0 4 -4 a = 0 a = 8 a = 12 f = 1 2 0 4 -4 12 a = 0 a = -8 a = -20 f = 1 2 0 4 -4 12 -20 a = 0 a = 24 a = 44 f = 1 2 0 4 -4 12 -20 44 a = 0 a = -40 a = -84 f = 1 2 0 4 -4 12 -20 44 -84 a = 0 a = 88 a = 172 f = 1 2 0 4 -4 12 -20 44 -84 172 a = 0 values = 1 2 0 4 -4 12 -20 44 -84 172

18   Pass
Init = [0, 1]; Rules = [2, 1]; N = 1:10; values_correct = [0, 1, 1, 3, 5, 11, 21, 43, 85, 171]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 0 1 a = 0 a = 1 f = 0 1 1 a = 0 a = 2 a = 3 f = 0 1 1 3 a = 0 a = 2 a = 5 f = 0 1 1 3 5 a = 0 a = 6 a = 11 f = 0 1 1 3 5 11 a = 0 a = 10 a = 21 f = 0 1 1 3 5 11 21 a = 0 a = 22 a = 43 f = 0 1 1 3 5 11 21 43 a = 0 a = 42 a = 85 f = 0 1 1 3 5 11 21 43 85 a = 0 a = 86 a = 171 f = 0 1 1 3 5 11 21 43 85 171 a = 0 values = 0 1 1 3 5 11 21 43 85 171

19   Pass
Init = [1, 0, 2]; Rules = [-1 1 1]; N = 1:20; values_correct = [1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

t1 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 t2 = 1×0 empty double row vector t2 = 1×0 empty double row vector a = 0 f = 1 0 2 a = -1 a = -1 a = 1 f = 1 0 2 1 a = 0 a = 0 a = 2 a = 3 f = 1 0 2 1 3 a = 0 a = -2 a = -1 a = 2 f = 1 0 2 1 3 2 a = 0 a = -1 a = 2 a = 4 f = 1 0 2 1 3 2 4 a = 0 a = -3 a = -1 a = 3 f = 1 0 2 1 3 2 4 3 a = 0 a = -2 a = 2 a = 5 f = 1 0 2 1 3 2 4 3 5 a = 0 a = -4 a = -1 a = 4 f = 1 0 2 1 3 2 4 3 5 4 a = 0 a = -3 a = 2 a = 6 f = 1 0 2 1 3 2 4 3 5 4 6 a = 0 a = -5 a = -1 a = 5 f = 1 0 2 1 3 2 4 3 5 4 6 5 a = 0 a = -4 a = 2 a = 7 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 a = 0 a = -6 a = -1 a = 6 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 a = 0 a = -5 a = 2 a = 8 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 a = 0 a = -7 a = -1 a = 7 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 a = 0 a = -6 a = 2 a = 9 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 a = 0 a = -8 a = -1 a = 8 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 a = 0 a = -7 a = 2 a = 10 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 a = 0 a = -9 a = -1 a = 9 f = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 a = 0 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!