> #sfb oct 9, 2001 > sinPi4:=sin(Pi/4);cosPi4:=cos(Pi/4); > sinPi8:=sin(Pi/8);cosPi8:=cos(Pi/8); > # sin^2 x = (1 - cos 2x)^/2; > sinPi8:=solve(x^2=(1-cosPi4)/2); > sinPi8:=solve(x^2=(1-cosPi4)/2)[1]; > op(4,eval(sin));#For advanced use only > sin(Pi/8):=sinPi8; > # two plots on the same line > with(plots): > F:=plot(sin(x),x=0..2*Pi,title="sin(x)",legend="sin(x)",linestyle=2): > G:=plot(cos(x),x=0..2*Pi,title="cos(x)",legend="cos(x)",linestyle=3): > display(array([F,G])); > display([F,G]); > F; > G; > ##### > #Sequence > a:=1/2^n;b:=1-1/2^n; > limit(a,n=infinity);limit(b,n=infinity); > seq(a,n=1..10); > sum(a,n=1..10); > subs(n=10,b); > with(student); > Sum(a,n=1..10); > f:=1/2^x;#f:=1/x; > F:=leftbox(f,x=1..6,5):display(F,title="leftsum"); > G:=rightbox(f,x=1..6,5):display(G,title="rightsum"); > display(array([F,G])); > restart;with(student):with(plots): > ## The integral test: Given f(x)>=0 non-increasing defined x>=1 > ## Let a_n = f(n), then the fate of > Sum(f(n),n=1..infinity),Int(f(x),x=1..infinity); > # are the same. Either both converge or both diverge. > Sum(1/n^2,n=1..infinity)=sum(1/n^2,n=1..infinity); > Int(1/x^2,x=1..infinity)=int(1/x^2,x=1..infinity); > evalf(Pi^2/6); > ## other tests > Sum(a[n],n=1..infinity); > #converges implies that > Limit(a[n],n=infinity)=0; > #comparison > 0 <= a[n]; a[n] <= b[n]; > Sum(a[n],n=1..infinity), "diverges implies", Sum(b[n],n=1..infinity), "diverges also"; > Sum(b[n],n=1..infinity), "converges implies", Sum(a[n],n=1..infinity), "converges also"; > #RATIO test suppose > Limit(abs(a[n+1])/abs(a[n]),n=infinity) = L; > 0 <= L, L < 1," implies ",Sum(a[n],n=1..infinity),"converges"; > 1 < L," implies ",Sum(a[n],n=1..infinity),"diverges"; > L=1,"then the test fails"; > # > a:=1/2^i;Limit(subs(i=n+1,a)/subs(i=n,a),n=infinity)=limit(subs(i=n+1,a)/subs(i=n,a),n=infinity); > a:=1/i!;Limit(subs(i=n+1,a)/subs(i=n,a),n=infinity)=limit(subs(i=n+1,a)/subs(i=n,a),n=infinity); > a:=1/i;Limit(subs(i=n+1,a)/subs(i=n,a),n=infinity)=limit(subs(i=n+1,a)/subs(i=n,a),n=infinity); > a:=1/i^2;Limit(subs(i=n+1,a)/subs(i=n,a),n=infinity)=limit(subs(i=n+1,a)/subs(i=n,a),n=infinity); > # > #Power series sum c_n (x - a)^n or > a:='a';Sum(c[n]*(x-a)^n,n=1..infinity); > #examples > series(exp(x),x=0,10);series(ln(x),x=1,10);series(arctan(x),x=0,11);series(1/(1-x),x=0,10);# > # Apply the ratio test > Limit(abs(c[n+1]*(x-a)^(n+1))/abs(c[n]*(x-a)^n),n=infinity);# > # > f:=arctan(x);g:=array(1..5); > for i from 1 to 5 do g[i]:=convert(series(f,x=0,2*i+1),polynom); od; > n:=2;plot([f,g[1],g[2],g[3],g[4],g[5]],x=-n*Pi..n*Pi,y=-2..2); > plot([f,convert(series(f,x=0,41),polynom)],x=-6*Pi..6*Pi,y=-2..2); > plot([f,convert(series(f,x=0,41),polynom)],x=-6*Pi..6*Pi,y=-2..2,numpoints=2000); > f:=sqrt(x);plot([f,convert(series(f,x=2,41),polynom)],x=0..20,y=-2..20,numpoints=2000); > > # We are use to writing 1+2x+x^3 in the order x^3+2x+1 > # But from a power series viewpoint 1+2x+x^3 makes more sense > # because we are thinking of `small' x so x^3 is smaller than x. > # > # intervals/radius of convergence graphically > # > # Geometric series radius 1 > f:=1/(1-x);deg:=20;g:=convert(series(f,x=0,deg+1),polynom); > plot([f,g],x=-2..2,y=-2..6,thickness=[3,1],color=[red,blue]); > #radius 4 -- sqrt at 4 > f:=sqrt(x);deg:=33;g:=convert(series(f,x=4,deg+1),polynom); > plot([f,g],x=0..10,y=-2..4,thickness=[3,1],color=[red,blue]); > #why here? -- nice function with radius 1 > f:=arctan(x);deg:=20;g:=convert(series(f,x=0,deg+1),polynom); > plot([f,g],x=-5..5,y=-2..2,thickness=[3,1],color=[red,blue]); >