# Matlab problem explanation

Discussion in 'Homework Help' started by assassin2811, Feb 14, 2013.

1. ### assassin2811 Thread Starter New Member

Jan 19, 2013
2
0
Hi everyone, i have a problem :
[Σ(m=0 to m=10)] (m+1)[δ(n-2m) - δ(n-2m-1)] (0<=n<=25)

and after i google, i find the solution, and here is my link (http://www.mathworks.com/matlabcent...le-proakis-chapter-2-solutions/content/P201.m) :
n = [0:25];
x1 = zeros(1,26);
for m=0:10,
x1 = x1 + (m-1).*(impseq(2.*m,0,25)-impseq(2.*m+1,0,25));
end
subplot(3,2,1);
stem(n,x1);
title('Sequence in Problem 2.1a')

i understand the solution except for the second line and 4th line
why do they need to assign x1 = zero(1,26) and after that, they add x1 like you see in 4th line and they change to (m-1) instead of (m+1) in the problem

Can anyone explain clearly for me, i've just started learning matlab for 2 months. Thanks in advance

2. ### tshuck Well-Known Member

Oct 18, 2012
3,531
675
1.) They use zeros() to initialize the x1 vector to all zeros.

2.) It could be a mistake. You tell me, does the resulting plot look the way you expect it to? Graph is out by hand and see if the two look alike.

...this is the problem with simply finding the answer, you learn nothing about the material just trying to figure out how to understand what the answer works.

3. ### assassin2811 Thread Starter New Member

Jan 19, 2013
2
0
yes, it look the same after i change the (m-1) to (m+1)
do you know when do we use the zeros because in this next problem :
n = [-25:25];
x2 = n.^2.*(stepseq(-5,-25,25)-stepseq(6,-25,25)) + 10*impseq(0,-25,25) + 20*0.5.^n.*(stepseq(4,-25,25)-stepseq(10,-25,25));
subplot(3,2,2);
stem(n,x2);
title('Sequence in Problem 2.1b')
they don't assign x1 = zeros() like in the above problem

4. ### tshuck Well-Known Member

Oct 18, 2012
3,531
675
all zeros() does is initialize each element in an array/vector to 0, it isn't necessary in a lot of applications, provided each element is calculated out.

assassin2811 likes this.