# Matrix sequence go diagonal

2 views (last 30 days)
Ainars Cernavskis on 18 Jul 2021
Edited: Jan on 20 Jul 2021
Hi am ,trying to write a function which would display following sequences diagnaly :
1,3,10,33,109,360 [EDITED]
But am not sure how to do that , i have done a little bit,but am now stuck ( am kinda new to matlab and was just trying to learn it for the future ), any help would be great .
Or even if you could show me a refference which i could go of of , would be good too .
Ainars Cernavskis on 18 Jul 2021
@Jan i havent done muchs becasue am stuck ,and regarding elements i would like to produce 15 elements
n = input ('sequence_matrix_')
C = n
B = [1:C]*3
A = diag(B)

Image Analyst on 18 Jul 2021
This isn't your homework is it? Try this:
% 1,3,10,33,109,360
vec = [1,3,10,33,109,360]
for k = 1 : length(vec)
fprintf('%d, ', vec(k) + 3);
end
fprintf('\n');
You get:
vec =
1 3 10 33 109 360
4, 6, 13, 36, 112, 363,
Is that what you want? And why do you want this? What's the use case?
##### 2 CommentsShowHide 1 older comment
Image Analyst on 19 Jul 2021

Jan on 20 Jul 2021
Edited: Jan on 20 Jul 2021
n = 6; % Or if you want: input ('sequence_matrix_');
v = zeros(1, n+1); % Pre-allocation
v(2) = 1; % Initial values: [0, 1]
for k = 2:n
v(k + 1) = v(k) * 3 + v(k - 1);
end
v(1) = [] % Remove leading zero
v = 1×6
1 3 10 33 109 360