How do I shift and repeat the same function and then sum the total overlapping area under those curves?

2 次查看(过去 30 天)
I have a function which is similar to this
x=-10:0.1:10;
y=sqrt((36-x.^2)/9);
plot(x,y)
I would like to shift it by 1 and repeat this 20 times (so that I have as many repeats as values of x). I tried with things like circshift and this:
A=[1 2 3 4 5]
B=zeros(size(A));
n=1; %Shift units
B(n+1:end)=A(1:end-n)
but I'm stuck. Once I have that, I'd like to calculate the sum of all the overlapping areas in a certain range (say -10:0). But that is even further away from my skills... any tip is appreciated!

回答(1 个)

Walter Roberson
Walter Roberson 2017-11-3
x=-10:0.1:10;
A = sqrt((36-x.^2)/9);
N = length(x);
B = zeros(length(x) + N);
for shift = 1 : N
B(shift : shift+N-1) = B(shift : shift+N-1) + A;
end
plot(real(B))
  1 个评论
mr
mr 2017-11-7
Thanks! I now tried to do the same with a sin function, replacing the first two lines of your code with
x = -pi:0.01:pi;
A=sin(x);
I was expecting that there would be an optimal shift with 'worse result' (smaller peaks) either side of it. (intuitively, if the sin phases are shifted to the point where they overlap with each other they have destructive interference. But this doesn't seem to be the case. The smaller I make the shift the bigger the peaks become. Any idea if something in the code makes this result obvious? (I would really like to have and then test the destructive interference) thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by