How do I plot a summation equation?
6 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm trying to plot a summation equation from -50 to 50:
The range for the plot is k = +- 3 / delta x.
delta x isn't defined in the question but I chose 0.5.
I tried this but the graph doesn't seem to look right.
What is wrong and how do I fix this?
% define constant values below
xc = 0.5 ;
% Make m a vector
m = -50:50;
% Given function
h = @(k) xc.*exp(-i.*2.*pi.*k.*m.*xc) ;
k = -3. /xc : 1. /xc : 3. /xc ; % possible k values
p = zeros(size(k)) ; % save the sum for eac function
for i = 1:length(k)
v = h(k(i)) ;
p(i) = sum(v) ;
end
plot(k,p)
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 9 月 28 日
編集済み: Walter Roberson
2022 年 9 月 28 日
You are summing exp() of values that are purely imaginary and are mostly not integer multiples of π. The individual entries are going to be mostly complex values (except at the occasional π multiple.)
Your exp() values include negative and positive coefficients. Is it possible that the imaginary parts cancel?
If each exp(1i*K) term is exactly balanced by a corresponding -K and there is no round off error then the imaginary components would cancel over the sum.
k = -3. /xc : 1. /xc : 3. /xc ; % possible k values
Will that definitely exactly balance positive and negative? No, in the general case you need to expect round-off error as 1/xc accumulates. And you should not assume that sin(x) will exactly balance sin(-x), especially as you are not pairing them up. 0.1+0.2-0.3 is not exactly 0 in binary floating point.
So the sum will typically have a small imaginary component.
2 件のコメント
Walter Roberson
2022 年 9 月 28 日
Though I just noticed you sum over m -50 to +50. Same argument, you are going to have small imbalances.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!