Information Technology Reference
In-Depth Information
code should plot an approximation of
u
.x; T / for x
2
.0; L/. Compare the
results with those obtained in (e).
˘
Exercise 8.7.
In order to determine the Fourier coefficients of a function f.x/, x
2
.0; 1/, we have to compute integrals of the form
D
Z
1
0
c
k
f.x/sin.kx/
dx
k
D
1;2:::;
cf. (8.74)and(8.75). For many functions f , this can be tedious, difficult, and in
some cases impossible to do by hand. This is the case for functions such as
f.x/
D
e
x
2
;
f.x/
D
sin.e
cos.x/
/:
However, we can use the numerical techniques developed in Chap. 1 to compute
approximations of the Fourier coefficients. In this exercise we will write a computer
program that utilizes the trapezoidal rule to do so.
(a) Write a function that takes x as an input parameter and returns the number e
x
2
.
(b) Write a function
TrapRuleFourier
that takes the number of intervals n to use in
the trapezoidal rule, and a positive integer k as input parameters. The function
should call the function developed in (a) and return an approximation of the
Fourier coefficient c
k
for the function e
x
2
.
(c) Write a program that computes the N th partial sum of the Fourier series of e
x
2
.
It should take the integer N as input and plot the approximation.
(d) Run the program in (c) with N
D
10;100; 1;000 and compare the graph with
that of e
x
2
.
(e) Apply Simpson's rule instead of the trapezoidal rule and redo (b)-(d).
(f) Use formula (8.80) and the code developed in (a)-(e) to write a program that
computes an approximation of the formal solution of the problem
u
t
D
u
xx
for x
2
.0; 1/; t > 0;
u
x
.0; t /
D
u
x
.1; t /
D
0
for t>0;
u
.x; 0/
D
e
x
2
for x
2
.0; 1/:
The program should graph an approximation of
u
.x; 3/ for x
2
.0; 1/.
(g) Modify your program so that it computes an approximation of the formal
solution of
u
t
D
u
xx
for x
2
.0; 1/; t > 0;
u
x
.0; t /
D
u
x
.1; t /
D
0
for t>0;
u
.x; 0/
D
sin.e
cos.x/
/
for x
2
.0; 1/:
˘