I want to graph \$h[n] = \frac{1}{n+1} \ n\in [0,29] \$
I tried the next code, but won't compile:
n=linspace(0,29,30);
h =1/(1+n);
figure
stem (n,h);
I want to graph \$h[n] = \frac{1}{n+1} \ n\in [0,29] \$
I tried the next code, but won't compile:
n=linspace(0,29,30);
h =1/(1+n);
figure
stem (n,h);
You need to add a dot in front of the divide symbol (this means array divide as opposed to matrix divide):
n=linspace(0,29,30);
h =1./(1+n);
figure
stem (n,h);
Resulting Graph:

To find out more, type help . - you will get something like this (this is only part of the result, as it's rather long...):
>> help .
Operators and special characters.
Arithmetic operators.
plus - Plus +
uplus - Unary plus +
minus - Minus -
uminus - Unary minus -
mtimes - Matrix multiply *
times - Array multiply .*
mpower - Matrix power ^
power - Array power .^
mldivide - Backslash or left matrix divide \
mrdivide - Slash or right matrix divide /
ldivide - Left array divide .\
rdivide - Right array divide ./
n=0:30; is cleaner and easier. In practice, this error is solved by adding dots util it works. Eventually, you will know the cases in which it is needed.
– Serge
Jan 05 '13 at 16:36