You are on page 1of 10

Laborator 5 M.A.C.

1. Polinoame Taylor
Comanda "Series" da dezvoltarea in serie Taylor de puteri a unei functii. Polinomul Taylor de grad 4 asociat functiei
f in jurul punctului x0 este:
In[1]:=

Out[2]=

In[3]:=

Clear@"Global`*"D
Series@f@xD, 8x, x0, 4<D
f@x0D + f @x0D Hx - x0L +

1
2

f @x0D Hx - x0L2 +

1
6

fH3L @x0D Hx - x0L3 +

1
24

fH4L @x0D Hx - x0L4 + O@x - x0D5

Comenzile urmatoare tabeleaza si reprezinta grafic polinoamele Taylor de grad 1, 3, 5, 11 si 14 corespunzatoare

functiei f HxL = cos2 HxL, dezvoltarea fiind facuta in jurul punctului x = 4 :


Clear@"Global`*"D
f@x_D = Cos@xD2 ;

s@x_, n_D := NormalBSeriesBf@xD, :x,

, n>FF
4
tb = 881, s@x, 1D<, 83, s@x, 3D<, 85, s@x, 5D<, 811, s@x, 11D<, 814, s@x, 14D<<;
TableForm@tb, TableHeadings 8None, 8"n", "s@x,nD"<<, TableSpacing 82, 4<D

Out[7]//TableForm=

s@x,nD

1
2

-x

1
2

-x+

2
3

1
2

-x+

2
3

11

1
2

-x+

2
3

14

1
2

-x+

2
3

IIII-

+ xM

+ xM -

+ xM -

+ xM -

2
15

2
15

2
15

III-

+ xM

+ xM +

+ xM +

4
315
4
315

II-

2 I- +xM

+ xM -

+ xM -

2 I- +xM

2835
4

2835

4 I- +xM

4 I- +xM

11

155 925
4 I- +xM

11

155 925

13

6 081 075

Laborator 5 MAC Aproximari polinomiale.nb

In[8]:=

Needs@"PlotLegends`"D
Plot@Evaluate@8s@x, 1D, s@x, 3D, s@x, 5D, s@x, 11D, s@x, 14D, f@xD<D, 8x, 0, 4<,
PlotStyle 88Dashing@80.05, 0.05<D<, 8Dashing@80.03, 0.03<D<, 8Dashing@80.01, 0.01<D<,
8Dashing@80.005, 0.005<D<, 8Dashing@80.003, 0.003<D<, 8Thickness@0.005D<<,
LegendPosition 81.1, - 0.5<, PlotLegend 8"s1 ", "s3 ", "s5 ", "s11 ", "s14 ", "f"<,
ImageSize LargeD
General::obspkg :
PlotLegends` is now obsolete. The legacy version being loaded may conflict with current Mathematica
functionality. See the Compatibility Guide for updating information.

s1
1
s3
Out[9]=

s5

s11
s14

-1

Comanda "Module" permite definirea unei functii de tip procedura :


In[39]:=

fTaylor@f_, p0_, n0_, a_, b_D :=


Module@8p = p0, n = n0<, gf = Plot@f@xD, 8x, a, b<, PlotStyle 8Red<D;
fT@x_D = Normal@Series@f@xD, 8x, p, n<DD;
gT = Plot@fT@xD, 8x, a, b<, PlotStyle 8Dashed, Thick, Blue<D;
Show@gf, gT, ImageSize Large, PlotLabel
Grid@88"In x =", p, "polinomul este PHxL =", Chop@fT@xDD<<, BaseStyle SmallDDD

Laborator 5 MAC Aproximari polinomiale.nb

In[11]:=

fTaylor@Sin, Pi 4, 5, 0, PiD
In x =

polinomul este PHxL =

Jx- N

5
4

120

Jx- N

24

Jx- N

Jx- N

x-

1
2

1.0

0.8

0.6
Out[11]=

0.4

0.2

0.5

1.0

1.5

2.0

2.5

Functia precedenta poate fi inclusa intr-o interfata grafica folosind comanda "Manipulate":

3.0

Laborator 5 MAC Aproximari polinomiale.nb

In[38]:=

Manipulate@fTaylor@f, p, n, 0, 2 PiD, 88n, 1, "Gradul polinomului Taylor"<, 1, 3, 1<,


88p, Pi 8, "Punctul in care se face aproximarea"<, 0, 2 Pi, Pi 24<,
88f, Sin, "Functia"<, 8Sin "sinus", Cos "cosinus"<<D
Gradul polinomului Taylor
Punctul in care se face aproximarea
Functia

sinus

cosinus

In x =
1.0

polinomul este PHxL = Jx - N cosJ N + sinJ N

0.5
Out[38]=

-0.5

-1.0

Exercitiul 1: Calculati si afisati polinomul Taylor de gradul 3 asociat functiei f HxL = x ,


dezvoltarea fiind facuta in jurul punctului x = 1. Reprezentati grafic pe aceeasi figura functia
impreuna cu polinomul asociat.

2. Polinoame Bernstein

In[40]:=

Polinoamele Berstein de ordinul n constituie o baza in spatiul polinoamelor de grad mai mic sau egal cu n si se
definesc astfel :
Bi,n HxL = Cni xi H1 - xLn-i , i = 0, 1, ..., n.

PBern@i_, n_, t_D = Binomial@n, iD t ^ i H1 - tL ^ Hn - iL;


nr = 5;
Do@v = 8<; Do@AppendTo@v, PBern@i, n, tDD, 8i, 0, n<D;
Print@"Polinoamele Bernstein de ordinul ", n, " sunt : ", TraditionalForm@vDD, 8n, 1, nr<D

Laborator 5 MAC Aproximari polinomiale.nb

Polinoamele Bernstein de ordinul 1 sunt : 81 - t, t<

Polinoamele Bernstein de ordinul 2 sunt : 9H1 - tL2 , 2 H1 - tL t, t2 =

Polinoamele Bernstein de ordinul 3 sunt : 9H1 - tL3 , 3 H1 - tL2 t, 3 H1 - tL t2 , t3 =

Polinoamele Bernstein de ordinul 4 sunt : 9H1 - tL4 , 4 H1 - tL3 t, 6 H1 - tL2 t2 , 4 H1 - tL t3 , t4 =


Polinoamele Bernstein de ordinul 5 sunt :
9H1 - tL5 , 5 H1 - tL4 t, 10 H1 - tL3 t2 , 10 H1 - tL2 t3 , 5 H1 - tL t4 , t5 =

Fiind data functia f : [0,1] R R , polinomul Bn f HxL = ni=0 f I n M Bi,n HxL se numeste polinom Bernstein asociat
i

In[43]:=

functiei f pe intervalul [0,1].


Comenzile urmatoare reprezinta grafic in cadrul unei interfete polinomul Bernstein de grad n corespunzator functiei
f HxL = cos2 HxL pe intervalul [0,1] :
faproxB@n0_D := Module@8nr = n0<, f1@x_D = HCos@xDL ^ 2;
g1 = Plot@f1@xD, 8x, 0, 1<, PlotStyle 8Red<D;
polB@x_, nr_D := Sum@f1@i nrD * PBern@i, nr, xD, 8i, 0, nr<D;
g2 = Plot@polB@x, nrD, 8x, 0, 1<, PlotStyle 8Green<D;
Show@g1, g2, PlotRange AllDD;
Manipulate@faproxB@nD, 8n, 2, 10, 1<D
n

1.0
0.9
0.8
Out[44]=

0.7
0.6
0.5
0.4

0.2

0.4

0.6

0.8

1.0

Exercitiul 2: Calculati si afisati polinomul Bernstein de gradul 3 asociat functiei


f HxL = cos2 H3 xL. Reprezentati grafic pe aceeasi figura functia impreuna cu polinomul asociat.

3. Polinoame Fourier
Polinomul Fourier de ordin k asociat pe intervalul [a,b] unei functii f HxL are expresia
sfHxL =
an =

a0
2

+ kn=1 Ian cosI

2 nx
M + bn
b-a

b
2
2 nx
f HxL cosI b-a M x,
b-a a

bn =

2 nx
MM
, unde
b-a
b
2
2 nx
f HxL sinI b-a M x.
b-a a

sinI

coeficientii

sunt

a0 =

b
2
f HxL x,
b-a a

Comenzile urmatoare construiesc acest polinom si il reprezinta graficpentrun cateva valori ale lui k (1, 2, 10, 50):

Laborator 5 MAC Aproximari polinomiale.nb

In[18]:=
In[19]:=

f@x_D = x ^ 2;
a0 = H2 PiL * Integrate@f@xD, 8x, 0, Pi<D
2 2

Out[19]=

In[20]:=

Out[20]=

an = H2 PiL * Integrate@f@xD * Cos@2 * n * xD, 8x, 0, Pi<D


an = Simplify@an, Assumptions -> n IntegersD
2 n Cos@2 n D + I- 1 + 2 n2 2 M Sin@2 n D
2 n3

1
Out[21]=

n2

In[22]:=

Out[22]=

bn = H2 PiL * Integrate@f@xD * Sin@2 * n * xD, 8x, 0, Pi<, Assumptions n IntegersD


bn = Simplify@bn, Assumptions -> n IntegersD
- 1 + I1 - 2 n2 2 M Cos@2 n D + 2 n Sin@2 n D
2 n3

Out[23]=

In[24]:=

sf@x_, k_D := a0 2 + Sum@an * Cos@2 * n * xD + bn * Sin@2 * n * xD, 8n, 1, k<D;


Plot@8sf@x, 1D, f@xD<, 8x, 0, Pi<D
Plot@8sf@x, 2D, f@xD<, 8x, 0, Pi<D
Plot@8sf@x, 10D, f@xD<, 8x, 0, Pi<D
Plot@8sf@x, 50D, f@xD<, 8x, 0, Pi<D
10

6
Out[25]=

0.5

1.0

1.5

2.0

2.5

3.0

Laborator 5 MAC Aproximari polinomiale.nb

10

6
Out[26]=

0.5

1.0

1.5

2.0

2.5

3.0

0.5

1.0

1.5

2.0

2.5

3.0

0.5

1.0

1.5

2.0

2.5

3.0

10

6
Out[27]=

10

6
Out[28]=

Comenzile urmatoare tabeleaza si reprezinta grafic polinoamele Fourier de ordin 1, 2 si 3:

Laborator 5 MAC Aproximari polinomiale.nb

In[29]:=

a = 0; b = Pi;
tb = 881, sf@x, 1D<, 82, sf@x, 2D<, 83, sf@x, 3D<<;
TableForm@tb, TableHeadings 8None, 8"k", "sf"<<, TableSpacing 82, 4<D
Needs@"PlotLegends`"D

Plot@Evaluate@8f@xD, sf@x, 1D, sf@x, 2D, sf@x, 3D<D, 8x, a, b<,


PlotStyle 88Thickness@0.005D<, 8Dashing@80.05, 0.05<D<, 8Dashing@80.03, 0.03<D<,
8Dashing@80.01, 0.01<D<, 8Dashing@80.005, 0.005<D<, 8Dashing@80.003, 0.003<D<<,
LegendPosition 81.1, - 0.5<, PlotLegend 8 "f", "sf1 ", "sf2 ", "sf3 "<, ImageSize LargeD

Out[31]//TableForm=

sf

2
3
2

3
2
3

+ Cos@2 xD - Sin@2 xD
+ Cos@2 xD +

1
4

Cos@4 xD - Sin@2 xD -

+ Cos@2 xD +

1
4

Cos@4 xD +

1
9

1
2

Sin@4 xD

Cos@6 xD - Sin@2 xD -

1
2

Sin@4 xD -

1
3

Sin@6 xD

10

f
6

sf1

Out[33]=

4
sf2
2
sf3

0.5

1.0

1.5

2.0

2.5

3.0

In[34]:=

Clear@"Global`*"D

In[35]:=

seriaFourier@f_, a_, b_, k_D :=


Module@8a0, an, bn<, a0 = H2 Hb - aLL * Integrate@f@xD, 8x, a, b<D;
an = H2 Hb - aLL * Simplify@Integrate@f@xD * Cos@H2 * n * Pi * xL Hb - aLD, 8x, a, b<D,
Assumptions n IntegersD;
bn = H2 Hb - aLL * Simplify@Integrate@f@xD * Sin@H2 * n * Pi * xL Hb - aLD, 8x, a, b<D,
Assumptions n IntegersD;
sf@x_D := a0 2 + Sum@an * Cos@H2 * n * Pi * xL Hb - aLD +
bn * Sin@H2 * n * Pi * xL Hb - aLD, 8n, 1, k<D;
Plot@8f@xD, sf@xD<, 8x, a, b<, PlotStyle 88Thickness@0.005D<, 8Dashing@80.01, 0.01<D<<,
ImageSize LargeDD

Laborator 5 MAC Aproximari polinomiale.nb

In[36]:=

f@x_D = x ^ 3; seriaFourier@f, - 1, 1, 5D
1.0

0.5

Out[36]=

-1.0

-0.5

0.5

1.0

-0.5

-1.0
In[37]:=

f@x_D = x ^ 3; Manipulate@seriaFourier@f, - 1, 1, kD, 8k, 1, 20, 1<D


k

1.0

0.5

Out[37]=

-1.0

-0.5

0.5

-0.5

-1.0

1.0

10

Laborator 5 MAC Aproximari polinomiale.nb

Exercitiul 3: Calculati si afisati polinomul Fourier de ordin 10 asociat functiei f HxL = x 2 + x + 1


pe intervalul [0, 2]. Reprezentati grafic pe aceeasi figura functia impreuna cu polinomul
asociat.

4. Recapitulare pentru test

You might also like