CA I -Exercise sheet 03

Exercise 1: (Chebyschev polynomials)

(a)

Clear[T1];
T1[n_,x_]:=TrigExpand[Cos[n ArcCos[x]]]/;IntegerQ[n]&&n≥0

T1[6,x]

(b)

Clear[T2];
T2[n_,x_]:=Expand[1/2((x+Sqrt[x^2-1])^n+(x-Sqrt[x^2-1])^n)]/;IntegerQ[n]&&n≥0

T2[6,x]

(c)

Clear[T3];
T3[0,x_]:=1
T3[1,x_]:=x
T3[n_,x_]:=2x T3[n-1,x]-T3[n-2,x]/;IntegerQ[n]&&n≥2

T3[6,x]//Expand

(d)

Clear[T4];
$RecursionLimit=Infinity;
T4[0,x_]:=1
T4[1,x_]:=x
T4[n_,x_]:=(T4[n,x]=Expand[2x T4[n-1,x]-T4[n-2,x]])/;IntegerQ[n]&&n≥2

T4[6,x]

(e)

Clear[T5];
T5[0,x_]:=1
T5[1,x_]:=x
T5[n_,x_]:=Module[{pol1,pol2,temp},
pol1=1;
pol2=x;
Do[temp=pol2;pol2=Expand[2x pol2-pol1];pol1=temp,{n-1}];
pol2]/;IntegerQ[n]&&n≥2

T5[6,x]//Expand

Clear[T5Liste]
T5Liste[0,x_]:={1}
T5Liste[1,x_]:={1,x}
T5Liste[n_,x_]:=Module[{liste},
liste={1,x};
Do[AppendTo[liste,Expand[2x liste[[k]]-liste[[k-1]]]],{k,2,n}];
liste]/;IntegerQ[n]&&n≥2

T5Liste[6,x]

(f)

Clear[T6];
T6[0,x_]:=1
T6[1,x_]:=x
T6[n_,x_]:=Nest[{#[[2]],Expand[2x#[[2]]-#[[1]]]}&,{1,x},n-1][[2]]/;IntegerQ[n]&&n≥2

T6[6,x]

(g)

Clear[T7];
T7[0,x_]:=1
T7[1,x_]:=x
T7[n_,x_]:=(T7[n,x]=2 T7[n/2,x]^2-1)/;EvenQ[n]&&n≥2
T7[n_,x_]:=(T7[n,x]=2 T7[(n-1)/2,x]T7[(n+1)/2,x]-x)/;OddQ[n]&&n≥3

T7[6,x]//Expand

(h)

Timing[Table[T1[k,x],{k,0,100}];]

Timing[Table[T2[k,x],{k,0,100}];]

Timing[Table[T4[k,x],{k,0,100}];]

Timing[Table[T5[k,x],{k,0,100}];]

Timing[T5Liste[100,x];]

Timing[Table[T6[k,x],{k,0,100}];]

Timing[Table[T7[k,x],{k,0,100}];]

T7[100,x]

T1 and T2 are efficient, because only the comands implementet in the kern of Mathematica


T3 is unefficient, because all the intermediary results are several time computed



T4 computes only one time the intermediariy results and therefore is more efficient than T3


T5 is a very slow procedure


T6 use the efficient Nest procedure of Mathematica and therefore is also very efficient.


T7 is the fastest procedure, because in even case the problem is in hafl simplify


The Mathematica procedure ChebyshevT is also very efficient, but not faster as T7

(i)

The matter hier is at first to determine the 1.000.000-th polynomial  and  to evaluate it at the point 1 and not the other direction.    Its works as faster only with T7

T=T7[1000000,x];

T/.x->1