Page 494 - Applied Numerical Methods Using MATLAB
P. 494

CALCULUS   483
            G.2  CALCULUS

            G.2.1  Symbolic Summation
            We can use the symsum() function to obtain the sum of an indefinite/definite
            series as below.

            >>symsxnN %declare x,n,N as symbolic variables
            >>simple(symsum(n,0,N))
                                   N       N (N + 1)
               ans = 1/2*N*(N + 1) %  n=0  n =
                                              2
            >>simple(symsum(n^2,0,N))
                                            N   2   N (N + 1)(2N + 1)
               ans = 1/6*N*(N + 1)*(2*N + 1) %  n=0  n  =
                                                            6
            >>symsum(1/n^2,1,inf))
                                  1    π  2
                               N
               ans = 1/6*pi^2 %      =
                               n=0  n  2  6
            >>symsum(x^n,n,0,inf))
                                            1
                                  N   n
               ans = -1/(-1 + x) %   x  =       under the assumption that |x| < 1
                                 n=0      1 − x
            G.2.2  Limits
            We can use the limit() function to get the (two-sided) limit and the right/left-
            sided limits of a function as below.
            >>syms h n x
                                   sin x
            >>limit(sin(x)/x,x,0) % lim  = 1
                                x→0  x
              ans=1
                                          x
            >>limit(x/abs(x),x,0,’right’) % lim  = 1
                                      x→0 + | x|
              ans=1
                                         x
            >>limit(x/abs(x),x,0,’left’) % lim  =−1
                                     x→0 − |x|
              ans=-1
                                   x
            >>limit(x/abs(x),x,0) % lim  = ?
                                x→0 |x|
              ans = NaN  %Not a Number
                                            cos(x + h) − cos(x)  d
            >>limit((cos(x+h)-cos(x))/h,h,0) % lim           =    cosx =−sinx
                                         h→0        h           dx
              ans = -sin(x)
                                             x
                                                n
            >>limit((1 + x/n)^n,n,inf) % lim 1 +  = e x
                                    n→∞     n
              ans = exp(x)
            G.2.3  Differentiation
            The diff() function differentiates a symbolic expression w.r.t. the variable given
            as one of its 2 nd  or 3 rd  input arguments or its free variable which might be
            determined by using the findsym function.
   489   490   491   492   493   494   495   496   497   498   499