How to take the sum of a series of variables to a limit?

1 visualizzazione (ultimi 30 giorni)
What instruction can I use to plot the following sum of phasor in the form of variables with different values for N ?
%% Fourier coefficients
a_10 = (6)/(20*pi)*exp(pi/2);
a_9 = ((3*sqrt(2))/(18*pi))*exp(j*(3*pi/4))*exp(pi/2);
a_8 = 0;
a_7 = ((3*sqrt(2))/(14*pi))*exp(-j*(3*pi/4))*exp(pi/2);
a_6 = (6)/(12*pi)*exp(pi/2);
a_5 = ((3*sqrt(2))/(10*pi))*exp(j*(3*pi/4))*exp(pi/2);
a_4 = 0;
a_3 = (3*sqrt(2))/(6*pi)*exp(-j*(3*pi/4))*exp(pi/2);
a_2 = (6)/(4*pi)*exp(pi/2);
a_1 = ((3*sqrt(2))/(2*pi))*exp(j*(3*pi/4))*exp(pi/2);
a0 = -1/4;
a1 = ((3*sqrt(2))/(2*pi))*exp(j*(3*pi/4))*exp(pi/2);
a2 = (6)/(4*pi)*exp(pi/2);
a3 = (3*sqrt(2))/(6*pi)*exp(-j*(3*pi/4))*exp(pi/2);
a4 = 0;
a5 = ((3*sqrt(2))/(10*pi))*exp(j*(3*pi/4))*exp(pi/2);
a6 = (6)/(12*pi)*exp(pi/2);
a7 = ((3*sqrt(2))/(14*pi))*exp(-j*(3*pi/4))*exp(pi/2);
a8 = 0;
a9 = ((3*sqrt(2))/(18*pi))*exp(j*(3*pi/4))*exp(pi/2);
a10 = (6)/(20*pi)*exp(pi/2);
%% Function variables
t = linspace(0,1,101);
y0 = a0;
y4 = (sum(a)+sum(a_))*exp(j*2*pi*t); %sum for -4 to 4
y10 = (sum(a)+sum(a_))*exp(j*2*pi*t); %sum for -10 to 10
y20 = (sum(a)+sum(a_))*exp(j*2*pi*t); %sum for -20 to 20
subplot(411), plot(t,y0)
subplot(412), plot(t,y4)
subplot(413), plot(t,y10)
subplot(414), plot(t,y20)
I am unsure if this is actually possible when manually defining the variables so if anyone would know a shorthand version to do this it would be very helpful!

Risposte (1)

Torsten
Torsten il 5 Dic 2022
Modificato: Torsten il 5 Dic 2022
What's the underlying function with these Fourier coefficients ?
%% Fourier coefficients
a_(10) = (6)/(20*pi)*exp(pi/2);
a_(9) = ((3*sqrt(2))/(18*pi))*exp(j*(3*pi/4))*exp(pi/2);
a_(8) = 0;
a_(7) = ((3*sqrt(2))/(14*pi))*exp(-j*(3*pi/4))*exp(pi/2);
a_(6) = (6)/(12*pi)*exp(pi/2);
a_(5) = ((3*sqrt(2))/(10*pi))*exp(j*(3*pi/4))*exp(pi/2);
a_(4) = 0;
a_(3) = (3*sqrt(2))/(6*pi)*exp(-j*(3*pi/4))*exp(pi/2);
a_(2) = (6)/(4*pi)*exp(pi/2);
a_(1) = ((3*sqrt(2))/(2*pi))*exp(j*(3*pi/4))*exp(pi/2);
a0 = -1/4;
a(1) = ((3*sqrt(2))/(2*pi))*exp(j*(3*pi/4))*exp(pi/2);
a(2) = (6)/(4*pi)*exp(pi/2);
a(3) = (3*sqrt(2))/(6*pi)*exp(-j*(3*pi/4))*exp(pi/2);
a(4) = 0;
a(5) = ((3*sqrt(2))/(10*pi))*exp(j*(3*pi/4))*exp(pi/2);
a(6) = (6)/(12*pi)*exp(pi/2);
a(7) = ((3*sqrt(2))/(14*pi))*exp(-j*(3*pi/4))*exp(pi/2);
a(8) = 0;
a(9) = ((3*sqrt(2))/(18*pi))*exp(j*(3*pi/4))*exp(pi/2);
a(10) = (6)/(20*pi)*exp(pi/2);
T0 = 1;
t = (linspace(0,1,101)).';
i0 = 0:2:20;
y = zeros(numel(t),numel(i0));
icount = 0;
for i = i0
icount = icount + 1;
y(:,icount) = a0 + sum(a_(1:i/2).*exp(-j*2*pi*(1:i/2)/T0.*t)+a(1:i/2).*exp(j*2*pi*(1:i/2)/T0.*t),2);
end
figure(1)
plot(t,real(y))
figure(2)
plot(t,imag(y))

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by