Syntax of the equation below

y= (1./k)*(sin(k'*t))
this equation was used to find the sum of odd harmonics of sine wave. Can someone explain how this equation works?

Answers (1)

t = 0:.01:10;
figure
hold on
for k = 1:2:10
y = sin(k*t)/k;
plot(t,y)
end
Note that y = sin(f*t), f represents the frequency, here k (=f) takes only the odd frequencies. YOu can check that from the above plot.

3 Comments

siva kumar commented:
Above equation which i have written worked.So please tell me what is the significance of . and '. Thank you
It calculates 1/k*sin(k*t) for each k and sum's them. This is same as:
t = 0:.01:10;
k = 1:2:10 ;
% y= (1./k)*(sin(k'*t)) ;
%
% plot(t,y) ;
yy = zeros(size(t)) ;
for i = 1:length(k)
yy = yy+1/k(i)*sin(k(i)*t) ;
end
plot(t,yy)
.* stands for element by element multiplication; ' this stands for transpose.
This does not find the sum of the harmonics, only plots them individually.
. has no meaning of its own in the original code. ./ is the name of an operator that is different than the / operator. The / operator is formally named as mrdivide and it is algebraic matrix division with A/B being similar to A*pinv(B) where * is algebraic matrix multiplication. The ./ that was used is element-by-element division, so 1./[3 5 7] would give you [1/3 1/5 1/7]
' is complex conjugate transpose. In the special case of working with real values, that is equivalent to transpose . That is, it would switch between row vector and column vector, or column vector and row vector.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 10 Jul 2017

Commented:

on 10 Jul 2017

Community Treasure Hunt

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

Start Hunting!