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

2 vues (au cours des 30 derniers jours)
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!

Réponses (1)

Walter Roberson
Walter Roberson le 3 Nov 2017
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 commentaire
mr
mr le 7 Nov 2017
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!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by