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]:= Clear@"Global`*"D Series@f@xD, 8x, x0, 4<D Out[2]= f@x0D + f ¢ @x0DHx - x0L + 1 2 f ¢¢ @x0DHx - x0L 2 + 1 6 f H3L @x0DHx - x0L 3 + 1 24 f H4L @x0DHx - x0L 4 + O@x - x0D 5 Comenzile urmatoare tabeleaza si reprezinta grafic polinoamele Taylor de grad 1, 3, 5, 11 si 14 corespunzatoare functiei f HxL = cos 2 HxL, dezvoltarea fiind facuta in jurul punctului x = Π 4 : In[3]:= Clear@"Global`*"D f@x_D = Cos@xD 2 ; s@x_, n_D := NormalBSeriesBf@xD, :x, Π 4 ,n>FF 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= n s@x,nD 1 1 2 + Π 4 - x 3 1 2 + Π 4 - x + 2 3 I- Π 4 + xM 3 5 1 2 + Π 4 - x + 2 3 I- Π 4 + xM 3 - 2 15 I- Π 4 + xM 5 11 1 2 + Π 4 - x + 2 3 I- Π 4 + xM 3 - 2 15 I- Π 4 + xM 5 + 4 315 I- Π 4 + xM 7 - 2 I- Π 4 +xM 9 2835 + 4 I- Π 4 +xM 11 155925 14 1 2 + Π 4 - x + 2 3 I- Π 4 + xM 3 - 2 15 I- Π 4 + xM 5 + 4 315 I- Π 4 + xM 7 - 2 I- Π 4 +xM 9 2835 + 4 I- Π 4 +xM 11 155925 - 4 I- Π 4 +xM 13 6081075

Laborator 5 MAC Aproximari Polinomiale

Embed Size (px)

DESCRIPTION

Laborator 5 MAC Aproximari Polinomiale

Citation preview

Page 1: Laborator 5 MAC Aproximari Polinomiale

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]:= Clear@"Global`*"DSeries@f@xD, 8x, x0, 4<D

Out[2]= 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 = cos2HxL, dezvoltarea fiind facuta in jurul punctului x =

Π

4:

In[3]:= Clear@"Global`*"Df@x_D = Cos@xD2

;

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

4

, n>FF

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=

n s@x,nD

11

2+

Π

4- x

31

2+

Π

4- x +

2

3I-

Π

4+ xM3

51

2+

Π

4- x +

2

3I-

Π

4+ xM3

-2

15I-

Π

4+ xM5

111

2+

Π

4- x +

2

3I-

Π

4+ xM3

-2

15I-

Π

4+ xM5

+4

315I-

Π

4+ xM7

-2 I-

Π

4+xM9

2835+

4 I-Π

4+xM11

155 925

141

2+

Π

4- x +

2

3I-

Π

4+ xM3

-2

15I-

Π

4+ xM5

+4

315I-

Π

4+ xM7

-2 I-

Π

4+xM9

2835+

4 I-Π

4+xM11

155 925-

4 I-Π

4+xM13

6 081 075

Page 2: Laborator 5 MAC Aproximari Polinomiale

In[8]:= Needs@"PlotLegends`"DPlot@Evaluate@8s@x, 1D, s@x, 3D, s@x, 5D, s@x, 11D, s@x, 14D, f@xD<D, 8x, 0, 4<,PlotStyle ® [email protected], 0.05<D<, [email protected], 0.03<D<, [email protected], 0.01<D<,

[email protected], 0.005<D<, [email protected], 0.003<D<, [email protected]<<,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.

Out[9]=

1 2 3 4

-1

1

2

f

s14

s11

s5

s3

s1

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

2 Laborator 5 MAC Aproximari polinomiale.nb

Page 3: Laborator 5 MAC Aproximari Polinomiale

In[11]:= fTaylor@Sin, Pi � 4, 5, 0, PiD

Out[11]=

0.5 1.0 1.5 2.0 2.5 3.0

0.2

0.4

0.6

0.8

1.0

In x =Π

4

polinomul este PHxL =Jx-

Π

4

N5

120 2

+Jx-

Π

4

N4

24 2

-Jx-

Π

4

N3

6 2

-Jx-

Π

4

N2

2 2

+x-

Π

4

2

+1

2

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

Laborator 5 MAC Aproximari polinomiale.nb 3

Page 4: Laborator 5 MAC Aproximari Polinomiale

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

Out[38]=

Gradul polinomului Taylor

Punctul in care se face aproximarea

Functia sinus cosinus

1 2 3 4 5 6

-1.0

-0.5

0.5

1.0

In x =Π

8

polinomul este PHxL = Jx -Π

8

N cosJ Π

8

N + sinJ Π

8

N

� 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

Polinoamele Berstein de ordinul n constituie o baza in spatiul polinoamelor de grad mai mic sau egal cu n si se

definesc astfel :

Bi,nHxL = Cn

i × xi × H1 - xLn-i

, i = 0, 1, ..., n.

In[40]:= 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

4 Laborator 5 MAC Aproximari polinomiale.nb

Page 5: Laborator 5 MAC Aproximari Polinomiale

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

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

2=

Polinoamele Bernstein de ordinul 3 sunt : 9H1 - tL3, 3 H1 - tL2

t, 3 H1 - tL t2, t

3=

Polinoamele Bernstein de ordinul 4 sunt : 9H1 - tL4, 4 H1 - tL3

t, 6 H1 - tL2t2, 4 H1 - tL t

3, t

4=

Polinoamele Bernstein de ordinul 5 sunt :

9H1 - tL5, 5 H1 - tL4

t, 10 H1 - tL3t2, 10 H1 - tL2

t3, 5 H1 - tL t

4, t

5=

Fiind data functia f : [0,1] Ì R ® R , polinomul Bn f HxL = Úi=0

nf I i

nM × Bi,nHxL se numeste polinom Bernstein asociat

functiei f pe intervalul [0,1].

Comenzile urmatoare reprezinta grafic in cadrul unei interfete polinomul Bernstein de grad n corespunzator functiei

f HxL = cos2HxL pe intervalul [0,1] :

In[43]:= 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

Out[44]=

n

0.2 0.4 0.6 0.8 1.0

0.4

0.5

0.6

0.7

0.8

0.9

1.0

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

f HxL = cos2H3 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 =a0

2+ Ún=1

k Ian cosI 2 nΠx

b-aM + bn sinI 2 nΠx

b-aMM , unde coeficientii sunt a0 =

2

b-aÙa

bf HxL â x,

an =2

b-aÙa

bf HxL cosI 2 nΠx

b-aM â x, bn =

2

b-aÙa

bf HxL sinI 2 nΠx

b-aM â x.

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

Laborator 5 MAC Aproximari polinomiale.nb 5

Page 6: Laborator 5 MAC Aproximari Polinomiale

In[18]:= f@x_D = x^2;

In[19]:= a0 = H2 � PiL * Integrate@f@xD, 8x, 0, Pi<D

Out[19]=

2 Π2

3

In[20]:= an = H2 � PiL * Integrate@f@xD * Cos@2 * n * xD, 8x, 0, Pi<Dan = Simplify@an, Assumptions -> n Î IntegersD

Out[20]=

2 n Π Cos@2 n ΠD + I-1 + 2 n2 Π2M Sin@2 n ΠD

2 n3 Π

Out[21]=

1

n2

In[22]:= bn = H2 � PiL * Integrate@f@xD * Sin@2 * n * xD, 8x, 0, Pi<, Assumptions ® n Î IntegersDbn = Simplify@bn, Assumptions -> n Î IntegersD

Out[22]=

-1 + I1 - 2 n2 Π2M Cos@2 n ΠD + 2 n Π Sin@2 n ΠD

2 n3 Π

Out[23]= -

Π

n

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<DPlot@8sf@x, 2D, f@xD<, 8x, 0, Pi<DPlot@8sf@x, 10D, f@xD<, 8x, 0, Pi<DPlot@8sf@x, 50D, f@xD<, 8x, 0, Pi<D

Out[25]=

0.5 1.0 1.5 2.0 2.5 3.0

2

4

6

8

10

6 Laborator 5 MAC Aproximari polinomiale.nb

Page 7: Laborator 5 MAC Aproximari Polinomiale

Out[26]=

0.5 1.0 1.5 2.0 2.5 3.0

2

4

6

8

10

Out[27]=

0.5 1.0 1.5 2.0 2.5 3.0

2

4

6

8

10

Out[28]=

0.5 1.0 1.5 2.0 2.5 3.0

2

4

6

8

10

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

Laborator 5 MAC Aproximari polinomiale.nb 7

Page 8: Laborator 5 MAC Aproximari Polinomiale

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 ® [email protected]<, [email protected], 0.05<D<, [email protected], 0.03<D<,

[email protected], 0.01<D<, [email protected], 0.005<D<, [email protected], 0.003<D<<,LegendPosition ® 81.1, -0.5<, PlotLegend ® 8 "f", "sf1", "sf2", "sf3"<, ImageSize ® LargeD

Out[31]//TableForm=

k sf

1Π2

3+ Cos@2 xD - Π Sin@2 xD

2Π2

3+ Cos@2 xD +

1

4Cos@4 xD - Π Sin@2 xD -

1

2Π Sin@4 xD

3Π2

3+ Cos@2 xD +

1

4Cos@4 xD +

1

9Cos@6 xD - Π Sin@2 xD -

1

2Π Sin@4 xD -

1

3Π Sin@6 xD

Out[33]=

0.5 1.0 1.5 2.0 2.5 3.0

2

4

6

8

10

sf3

sf2

sf1

f

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 ® [email protected]<, [email protected], 0.01<D<<,ImageSize ® LargeDD

8 Laborator 5 MAC Aproximari polinomiale.nb

Page 9: Laborator 5 MAC Aproximari Polinomiale

In[36]:= f@x_D = x^3; seriaFourier@f, -1, 1, 5D

Out[36]=

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

In[37]:= f@x_D = x^3; Manipulate@seriaFourier@f, -1, 1, kD, 8k, 1, 20, 1<D

Out[37]=

k

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

Laborator 5 MAC Aproximari polinomiale.nb 9

Page 10: Laborator 5 MAC Aproximari Polinomiale

� Exercitiul 3: Calculati si afisati polinomul Fourier de ordin 10 asociat functiei f HxL = x2

+ x + 1

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

asociat.

4. Recapitulare pentru test

10 Laborator 5 MAC Aproximari polinomiale.nb