Writing a MATLAB script to calculate the values of x1[n], x2[n], x3[n], x4[n[ and x5[n] for โˆ’5 โ‰ค ๐‘› โ‰ค +5

์กฐํšŒ ์ˆ˜: 4 (์ตœ๊ทผ 30์ผ)
Jacob
Jacob 2023๋…„ 9์›” 26์ผ
๋‹ต๋ณ€: Sulaymon Eshkabilov 2023๋…„ 9์›” 26์ผ
I am trying to write MATLAB script to calculate the values of x1[n], x2[n], x3[n], x4[n[ and x5[n] for โˆ’5 โ‰ค ๐‘› โ‰ค +5 which I am unsure how to do this is what I have so far any help or tips is greatly appreciated!
n1=-5:5;
n=input('n:')
sum=0;
for i=1:n
sum=sum+i+i+i+i+i
end

๋‹ต๋ณ€ (1๊ฐœ)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023๋…„ 9์›” 26์ผ
If understood your question correctly, it can be done in this way with a loop or cumsum():
n1=-5:5;
% n=input('n = '); % Not supported in online MATLAB
% e.g.: n = 6
n=6;
sum=0;
for ii=1:numel(n1)
sum=sum+n1(ii);
x(ii)=sum;
end
fprintf('The value of x(%d) = %d \n', n, x(n))
The value of x(6) = -15
% or using cumsum()
x = cumsum(n1);
fprintf('The value of x(%d) = %d \n', n, x(n))
The value of x(6) = -15

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ MATLAB Coder์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by