Plotting multiple iterations of n on the same graph
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I am trying to plot my calculated Fourier series on a plot. I need to plot it with n equaling different amounts for (n=5,10,50,100,500) iterations. I have n=100 in my code, but i also need to plot n=5,10,50,100, and 500. Is there a simpler way to do this than doing a hold off and re-entering my for loop specifying a different n?
clear all
clc;
%Define initial Values
T=0.004;
F0=12e+4;
n=100;
% Define t
t=linspace(-T,2*T,101);
% Calculate Fourier series
% a_0/2
F=5*F0/12;
for i=1:n
% F=F+a_i*sin(omega_i*t)+B_i*cos(omega_i*t)
F=F+(2*F0/(3*(pi*i).^2))*((4*cos(pi*i/2)-5*cos(pi*i)+6*cos(3*pi*i/2)-3*cos(2*pi*i)-2)*cos(2*pi*i/T*t)+(4*sin(pi*i/2)-5*sin(pi*i)+6*sin(3*pi*i/2)-3*sin(2*pi*i))*sin(2*pi*i/T*t));
end
figure
plot(t,F)
xlabel('t (s)')
ylabel('F (N)')
title('Fourier series for F(t) using a_i and b_i')
Réponses (0)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!