Java Printing

O restart;
Homework 1 Question 5
Part a)
4
O Fdx ;
F := x4
int x4$sin
O a n d
int
an := K
n
4
sin
n$Pi $ x
, x = 0 ..Pi
Pi
2
n$Pi $ x
, x = 0 ..Pi
Pi
1
Kcos n π sin n π Cn π
4
4
(1)
;
2
2 K24 K12 n2 cos n π π C24 n sin n π π
3
3
C24 cos n π Cn cos n π π K4 n sin n π π
n$ Pi $ x
, n = 1 ..10 :
Pi
F, Fsin , x = 0 ..Pi ;
O Fsin := sum a n $ sin
O plot
90
80
70
60
50
40
30
20
10
0
1
2
x
3
(2)
O restart;
4
O Fdx ;
F := x4
n$Pi $ x
, x = 0 ..Pi
Pi
O a n d
;
2
n$Pi $ x
int cos
, x = 0 ..Pi
Pi
2
1
2
an := 4
2 K12 n sin n π π K24 n cos n π π C24 sin n π
n cos n π sin n π Cn π
(3)
int x4$cos
4
4
(4)
3
3
Cn sin n π π C4 n cos n π π
O Fcos d sum a n $cos
O b 0 :=
n$ Pi $ x
, n = 1 ..10 :
Pi
1
4
int x , x = 0 ..Pi ;
Pi K0
b0 :=
O Fcos1 d b 0 CFcos :
O plot F, Fcos1 , x = 0 ..Pi ;
1 4
π
5
(5)
90
80
70
60
50
40
30
20
10
0
0
1
2
3
x
O restart;
Part b)
5
O Fdx ;
5
F := x
int x5$sin
O a n d
int
an := K
sin
n$Pi $ x
, x = 0 ..Pi
Pi
2
n$Pi $ x
, x = 0 ..Pi
Pi
1
n
5
Kcos n π sin n π Cn π
3
3
(6)
;
5
5
2 120 n cos n π π Cn cos n π π
2
2
4
4
K20 n cos n π π K120 sin n π C60 n sin n π π K5 n sin n π π
n$ Pi $ x
, n = 1 ..10 :
Pi
F, Fsin , x = 0 ..Pi ;
O Fsin := sum a n $ sin
O plot
(7)
300
200
100
0
1
2
3
x
O restart;
5
O Fdx ;
F := x5
(8)
n$Pi $ x
, x = 0 ..Pi
Pi
;
O a n d
2
n$Pi $ x
int cos
, x = 0 ..Pi
Pi
5
1
an := 5
2 K120 C120 sin n π n π Cn5 sin n π π
n cos n π sin n π Cn π
int x5$cos
3
2
(9)
4
K20 n3 sin n π π C120 cos n π K60 n2 cos n π π C5 n4 cos n π π
O Fcos d sum a n $cos
O b 0 :=
n$ Pi $ x
, n = 1 ..10 :
Pi
1
5
int x , x = 0 ..Pi ;
Pi K0
b0 :=
O Fcos1 d b 0 CFcos :
1 5
π
6
(10)
O plot
F, Fcos1 , x = 0 ..Pi ;
300
200
100
0
0
1
2
3
x
O restart;
Part c)
4
O Fdx ;
4
F := x
int x4$sin
O a n d
int
sin
O Fsin := sum a n $ sin
n$Pi $ x
, x =KPi ..Pi
Pi
2
n$Pi $ x
, x =KPi ..Pi
Pi
an := 0
n$ Pi $ x
, n = 1 ..10 ;
Pi
Fsin := 0
(11)
;
(12)
(13)
O restart;
O F d x4;
(14)
F := x4
(14)
n$Pi $ x
, x =KPi ..Pi
Pi
O a n d
;
2
n$Pi $ x
int cos
, x =KPi ..Pi
Pi
2
1
an := 4
2 K12 n2 sin n π π K24 n cos n π π C24 sin n π
n cos n π sin n π Cn π
int x4$cos
4
4
(15)
3
3
Cn sin n π π C4 n cos n π π
O Fcos d sum a n $cos
O b 0 :=
n$ Pi $ x
, n = 1 ..10 :
Pi
1
4
int x , x =KPi ..Pi ;
Pi CPi
b0 :=
1 4
π
5
(16)
O Fcos1 d b 0 CFcos :
O Fsum d Fsin CFcos1 :
O plot F, Fsum , x =KPi ..Pi ;
90
80
70
60
50
40
30
20
10
K3
K2
K1
0
1
2
x
3
O restart;
5
O F d x ; assume n,'integer'
int F$sin
O a n d
int
sin
F := x5
n$Pi $ x
, x =KPi ..Pi
Pi
2
n$Pi $ x
, x =KPi ..Pi
Pi
an~ :=
O Fsin := sum a n $ sin
2 K1
1 C n~
4
(17)
;
2
4
2
π n~ K20 π n~ C120
n~5
(18)
n$ Pi $ x
, n = 1 ..10 :
Pi
O
O F d x5;
5
F := x
n$Pi $ x
, x =KPi ..Pi
Pi
2
n$Pi $ x
cos
, x =KPi ..Pi
Pi
bn~ := 0
(19)
int x5$cos
O b n d
int
O Fcos d sum b n $cos
O b 0 :=
n$ Pi $ x
, n = 1 ..10 ;
Pi
Fcos := 0
;
(20)
(21)
1
int x5, x =KPi ..Pi ;
Pi CPi
b0 := 0
(22)
Fcos1 := 0
(23)
O Fcos1 d b 0 CFcos;
O Fsum2 d Fsin CFcos1 :
O plot F, Fsum2 , x =KPi ..Pi ;
300
200
100
K3
K2
0
K1
1
2
3
x
K100
K200
K300
O
It can be seen that increasing the number of terms allows the approximating functions to come closer to
the actual functions. It can also be seen that the sum of the functions is very acurate in approximating
the actual functions. The symmetry in x^4 (even function) allows the functions to give a better
approximation than the x^5 (odd function) which is constantly alternating signs.