필터 지우기
필터 지우기

Matrix sequence go diagonal

조회 수: 2 (최근 30일)
Ainars Cernavskis
Ainars Cernavskis 2021년 7월 18일
댓글: Rena Berman 2023년 11월 27일
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 .
  댓글 수: 6
Sam Chak
Sam Chak 2023년 11월 23일
The original question may be beneficial for people who wish to learn how to fill a vector sequence with desired values.
Rena Berman
Rena Berman 2023년 11월 27일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 7월 18일
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
Ainars Cernavskis
Ainars Cernavskis 2021년 7월 18일
@Image Analyst No this isnt homework , am just going to university next year and on of the modules is Matlab/simulink ,and i just wanted to ,try it out . Ive found some questions online which asks you make a funciton ,but it dosent show you the answear so i was wondering i could find the correct answear here or something similar to help me out a little bit . and see how everything works .And thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2021년 7월 20일
편집: Jan 2021년 7월 20일
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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by