# Matlab syntax help using fourier series & vectors

I'm trying to understand some matlab code. It's the fourier series approximation of a signal. This is my first time using matlab, so I guess I'm really trying to comprehend the syntax.

For my example, I am using some code I googled (http://www.ee.nmt.edu/~wedeward/EE341/FA97/example8.html)

Code:
01 N = 11;                            % summation limit (use N odd)
02 wo = pi;                           % fundamental frequency (rad/s)
03 c0 = 0;                            % dc bias
04 t = -3:0.01:3;                     % declare time values
05
06 yce = c0*ones(size(t));            % initialize yce to c0
07
08 for n = -N:2:N,                    % loop over series index n
09   cn = 2/(j*n*wo);                 % Fourier Series Coefficient
10   yce = yce + cn*exp(j*n*wo*t);    % Fourier Series computation
11 end

What I don't understand is the yce = yce + .... line (line 10). On that line you have
yce [vector]
cn [scalar]
j [scalar]
n [scalar]
wo [scalar]
t [vector]

So what does
vector = vector + scalar * exp(scalar * scalar * scalar * vector)
really evaluate to in matlab?

Does exp(vector) really mean it creates a new vector with entries:
e^old_vec_entry_for_t0
e^old_vec_entry_for_t1
....
e^old_vec_entry_for_tn

If so, then it makes sense as then it resolves to
vector = vector + scalar*vector

which is then

vector_running_sum = vector_running_sum + vector_values_for_all_t_from_neg_n_to_pos_n

Last edited:

## Answers and Replies

MATLABdude
Science Advisor
Your interpretation is correct. When you do vectorB=exp(vectorA), it produces a vector of the same size as vectorA containing the exponents of each of the values in vectorA.

This is an element-wise operator. Sometimes, you need to specify (usually by preceding the operator with a period, for instance ./ is element-wise division). For more, see:
http://www.cyclismo.org/tutorial/matlab/operations.html