Hi!(adsbygoogle = window.adsbygoogle || []).push({});

Here is my m-file for Fourier series plot:

clear

clc

syms n

a0=input('Enter coefficient a0: ');

an=input('Enter coefficient an: ');

bn=input('Enter coefficient bn: ');

a=input('Enter lower boundary: ');

b=input('Enter upper boundary: ');

t=linspace(a,b,10000);

sum=0;

for n=1:10 %%n could be any number, bigger n - better approximation

sum=sum+(subs(an,'n',n).*cos(2.*n.*pi.*t./(b-a))+subs(bn,'n',n).*sin(2.*n.*pi.*t./(b-a)));

end

series=a0+sum;

plot(t,series)

grid

Problem is, it is so slow! How should I modify it in order to increase speed?

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Plot fourier series in matlab

**Physics Forums | Science Articles, Homework Help, Discussion**