Diferenciál, Taylorův polynom 

Příklad 1 

Pomocí diferenciálu vypočtěte přibližně 29 stupňů. Namalujte graf, na kterém bude původni funkce a funkce použitá k aproximaci. 

> f:=x->sin(x);
 

(Typesetting:-mprintslash)([f := proc (x) options operator, arrow; sin(x) end proc], [proc (x) options operator, arrow; sin(x) end proc]) 

> x0:=Pi/6;
 

(Typesetting:-mprintslash)([x0 := 1/6*Pi], [1/6*Pi]) 

> xx:=29*Pi/180;
 

(Typesetting:-mprintslash)([xx := 29/180*Pi], [29/180*Pi]) 

> evalf(xx);
 

.5061454831 

> h:=xx-x0;
 

(Typesetting:-mprintslash)([h := -1/180*Pi], [-1/180*Pi]) 

> dx:=D(f);
 

(Typesetting:-mprintslash)([dx := cos], [cos]) 

> f(x0)+dx(x0)*h;
 

1/2-1/360*3^(1/2)*Pi 

> evalf(%);
 

.4848850053 

> evalf(sin(29*Pi/180));
 

.4848096203 

> df:=f(x0)+dx(x0)*(x-x0);
 

(Typesetting:-mprintslash)([df := 1/2+1/2*3^(1/2)*(x-1/6*Pi)], [1/2+1/2*3^(1/2)*(x-1/6*Pi)]) 

> plot([f(x), df], x=0..Pi/2);
 

Plot 

Příklad 2 

> restart;
 

Vypočtěte přibližně arccotg 1,02. Stejně jako v předcházejícím příkladě namalujte grafy obou funkcí.  

> f:=x->arccot(x);
 

(Typesetting:-mprintslash)([f := proc (x) options operator, arrow; arccot(x) end proc], [proc (x) options operator, arrow; arccot(x) end proc]) 

> df:=D(f);
 

(Typesetting:-mprintslash)([df := proc (x) options operator, arrow; -1/(1+x^2) end proc], [proc (x) options operator, arrow; -1/(1+x^2) end proc]) 

> x0:=1;
 

(Typesetting:-mprintslash)([x0 := 1], [1]) 

> h:=0.02;
 

(Typesetting:-mprintslash)([h := 0.2e-1], [0.2e-1]) 

> f(x0)+df(x0)*h;
 

1/4*Pi-0.1000000000e-1 

> evalf(%);
 

.7753981635 

> evalf(arccot(1.02));
 

.7754974968 

> plot([f(x), f(x0)+df(x0)*(x-x0)], x=0.5..1.5);
 

Plot 

Příklad 3 

> restart;
 

Určete Taylorův polynom stupně 4 pro funkci f(x) = 1/(1+x)a x[0]=0. Namalujte graf zadané funkce a Taylorova polynomu. 

Dále vypočtěte chybu, které se dopustíte, pokud použijete T[4](x) pro výpočet funkční hodnoty f(.5). Namalujte graf chyby pro 〉. 

> f:=x->1/(1+x);
 

(Typesetting:-mprintslash)([f := proc (x) options operator, arrow; 1/(1+x) end proc], [proc (x) options operator, arrow; 1/(1+x) end proc]) 

> x0:=0;
 

(Typesetting:-mprintslash)([x0 := 0], [0]) 

> c0:=f(x0);
 

(Typesetting:-mprintslash)([c0 := 1], [1]) 

> c1:=D(f)(x0)*(x-x0)/1!;
 

(Typesetting:-mprintslash)([c1 := -x], [-x]) 

> c2:=D[1,1](f)(x0)*(x-x0)^2/2!;
 

(Typesetting:-mprintslash)([c2 := x^2], [x^2]) 

> c3:=D[1,1,1](f)(x0)*(x-x0)^3/3!;
 

(Typesetting:-mprintslash)([c3 := -x^3], [-x^3]) 

> c4:=D[1,1,1,1](f)(x0)*(x-x0)^4/4!;
 

(Typesetting:-mprintslash)([c4 := x^4], [x^4]) 

> c4:=(D@@4)(f)(x0)*(x-x0)^4/4!;
 

(Typesetting:-mprintslash)([c4 := x^4], [x^4]) 

> tn:=(n, x0)->(D@@n)(f)(x0)*(x-x0)^n/n!;
 

(Typesetting:-mprintslash)([tn := proc (n, x0) options operator, arrow; ((`@@`(D, n))(f))(x0)*(x-x0)^n/factorial(n) end proc], [proc (n, x0) options operator, arrow; ((`@@`(D, n))(f))(x0)*(x-x0)^n/fac... 

> tn(4,0);
 

x^4 

> T4:=c0+c1+c2+c3+c4;
 

(Typesetting:-mprintslash)([T4 := 1-x+x^2-x^3+x^4], [1-x+x^2-x^3+x^4]) 

> plot([f(x), T4], x=-1..1, y=0..100, color=[red, blue]);
 

Plot 

> taylor(f(x), x=x0, 5);
 

series(1-x+x^2-x^3+x^4+O(x^5),x,5) 

> whattype(%);
 

series 

> convert(%%, polynom);
 

1-x+x^2-x^3+x^4 

> readlib(mtaylor);
 

proc () local f, k, v, m, n, s, t, w; option `Copyright (c) 1991 by the University of Waterloo. All rights reserved.`; f := args[1]; v := args[2]; if type(v, set) then v := [op(v)] elif not type(v, li... 

> T:=unapply(mtaylor(f(x), x=x0, 5),x);
 

(Typesetting:-mprintslash)([T := proc (x) options operator, arrow; 1-x+x^2-x^3+x^4 end proc], [proc (x) options operator, arrow; 1-x+x^2-x^3+x^4 end proc]) 

> evalf(abs(f(0.5)-T(0.5)));
 

0.208333333e-1 

> plot(abs(f(x)-T(x)), x=-1..1, y=0..100);
 

Plot 

Příklad 4 

Napište Taylorův polynom 3. stupně v bodě x[0]=0 funkce f(x)=tgx.  

> f:=x->tan(x);
 

(Typesetting:-mprintslash)([f := proc (x) options operator, arrow; tan(x) end proc], [proc (x) options operator, arrow; tan(x) end proc]) 

> derivace1:=D(f);
 

(Typesetting:-mprintslash)([derivace1 := proc (x) options operator, arrow; 1+tan(x)^2 end proc], [proc (x) options operator, arrow; 1+tan(x)^2 end proc]) 

> derivace2:=(D@@2)(f);
 

(Typesetting:-mprintslash)([derivace2 := proc (x) options operator, arrow; 2*tan(x)*(1+tan(x)^2) end proc], [proc (x) options operator, arrow; 2*tan(x)*(1+tan(x)^2) end proc]) 

> derivace3:=(D@@3)(f);
 

(Typesetting:-mprintslash)([derivace3 := proc (x) options operator, arrow; 2*(1+tan(x)^2)^2+4*tan(x)^2*(1+tan(x)^2) end proc], [proc (x) options operator, arrow; 2*(1+tan(x)^2)^2+4*tan(x)^2*(1+tan(x)^... 

> TayloruvPolynom[3]:=f(0)+derivace1(0)*x+derivace2(0)*x^2/(2!)+derivace3(0)*x^3/(3!);
 

(Typesetting:-mprintslash)([TayloruvPolynom[3] := x+1/3*x^3], [x+1/3*x^3]) 

> TaylorPol:=(f,x0,n)->sum((D@@i)(f)(x0)/i!*(x-x0)^i,i=0..n);
 

(Typesetting:-mprintslash)([TaylorPol := proc (f, x0, n) options operator, arrow; sum(((`@@`(D, i))(f))(x0)*(x-x0)^i/factorial(i), i = 0 .. n) end proc], [proc (f, x0, n) options operator, arrow; sum(... 

> TaylorPol(f,0,3);
 

x+1/3*x^3 

> taylor(f(x), x=0, 4);
 

series(x+1/3*x^3+O(x^4),x,4) 

> convert(%, polynom);
 

x+1/3*x^3 

> plot([f(x), TayloruvPolynom[3]], x=-Pi/3..Pi/3);
 

Plot 

> plot(abs(f(x)-TaylorPol(f,0,3)), x=-1..1);
 

Plot 

>