# Plotting the Fourier series in Matlab

1. Jul 18, 2012

### miss_t

I am very confused on how to start this problem, would highly appreciate some help!
Consider the function
f(x)=   0, -1≤x≤0
2x, 0≤x≤1.

The Fourier series coefficients for this function are given by [a][/0]=0.5, and for  k=1, 2, 3,...

[a][/k]=(2((-1)^k-1))/(k∏)^2 and [/k]=(2(-1)^(k+1))/k∏
.
Write a Matlab program to obtain three Figures:
(a) Figure 1 must contain a plot of the function f(x).
(b) Figure 2 must contain four subplots, arranged in a 2 X 2 grid. Each subplot must contain a plot of ,[g][/N](x)
one for each value of N= 1, 3, 7, 20.
(c) Figure 3 must contain a plot of f(x), and ,[g][/N](x) for N=  1, 3, 7, 20, all superimposed. Use a suitable
legend to identify the five plots in the figure.
In each case, make sure you use a suitable title, and labels for the axes. Pick at least 100 points from the interval
[-1, 10] so that you get a smooth looking plot.

2. Jul 18, 2012

### chiro

Hey miss_t and welcome to the forums.

This looks like a class problem, so I'll ask you what information have you been given in terms of the MATLAB functions.

Have you been given a reference guide by your tutors/lecturers? How much programming experience do you have whether its using C or something like MATLAB/Maple/Mathematica or some other mathematics computer package?

Basically what happens commonly is that the package creators provide documentation and help on all the commands that you can use as well as the parameters and then you just read the help file and do what you need to do, but if you haven't had any kind of programming experience this may seem daunting.