Kurt's Octave Assignment: Difference between revisions
Jump to navigation
Jump to search
(Created page with 'Useful Octave Templates TODO: finish') |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Useful Octave Templates |
=Useful Octave Templates= |
||
=====Fourier Series===== |
|||
TODO: finish |
|||
clf; %Clear Figure |
|||
t=0:.01:10; %Limits of the graph |
|||
T=2*pi %Definition of the period |
|||
M=1000 %Number of iterations to undergo |
|||
sum1=0; %Initialize the sum to 0<br> |
|||
%----------FOURIER SERIES----------% |
|||
for m=1:1:M, %For m=1, increment by 1 until you get to M |
|||
if(m!=0) |
|||
sum1 = sum1 + ((2/(pi*m))-(2/(pi*m))*cos(m*pi))*sin(m*2*pi/T*t); |
|||
end |
|||
end<br> |
|||
%---------------PLOT---------------% |
|||
plot(t,real(sum1),'b-') |
|||
title('Fourier Series Representation of a Wave') |
|||
xlabel('time (seconds)') |
|||
ylabel('Function') |
|||
grid on;<br> |
|||
legend(num2str(M) ' terms ') |
|||
print("squarewave.png","-dpng") % Prints the plot to a png file called squarewave.png |
Latest revision as of 15:04, 1 November 2010
Useful Octave Templates
Fourier Series
clf; %Clear Figure t=0:.01:10; %Limits of the graph T=2*pi %Definition of the period M=1000 %Number of iterations to undergo sum1=0; %Initialize the sum to 0
%----------FOURIER SERIES----------% for m=1:1:M, %For m=1, increment by 1 until you get to M if(m!=0) sum1 = sum1 + ((2/(pi*m))-(2/(pi*m))*cos(m*pi))*sin(m*2*pi/T*t); end end
%---------------PLOT---------------% plot(t,real(sum1),'b-') title('Fourier Series Representation of a Wave') xlabel('time (seconds)') ylabel('Function') grid on;
legend(num2str(M) ' terms ') print("squarewave.png","-dpng") % Prints the plot to a png file called squarewave.png