Limits

Contents

Symbolic Toolbox

In class, we just started learning how to calculate limits. So, of course we want to learn how to look at limits with Matlab. To begin, let's start where we ended. Upto this point, we have learned how to plot general functions in Matlab. However, everytime we change our x-values, we would have to redefine our y-values. This poses an interesting question, "How do you store a function f(x) and continue to input different values in Matlab?" In order to do this, you have to invoke the symbolic toolbox in Matlab. This is easy to do. To assign a symbolic variable, you just have to use the command syms. For example,

syms a x

will create two symbolic variables a and x. Now, we can create a function

F = a*sin(x)
 
F =
 
a*sin(x)
 

This creates a symbolic function F(a,x) = a sin(x). Now, you can evaluate F for a=5 and x=pi/2 by using the command subs which stands for 'substitute'

subs(F,{a,x},{5,pi/2})
ans =

     5

you will see that the answer is 5. So, what is going on? Basically, subs requires 3 inputs. The first input is the function. In our case, the function was stored in the symbolic variable F. The second input lists the variables that we want to substitute. In our case, the variables were a and x. Finally, the third input is what you want to substitute. In our case, we wanted a=5 and x=pi/2.

You can also see the result of a function for a series of values. Suppose you want to know the values of the function f(X) = 1/X for 5 equally spaces points between 1 and 5. We can do this easily in Matlab

syms X
f = 1./X
 
f =
 
1/X
 
subsX = linspace(1,5,5)
subsX =

     1     2     3     4     5

subs(f,X,subsX)
ans =

    1.0000    0.5000    0.3333    0.2500    0.2000

Calculating Limits

Now we have all the tools necessary to look at limits in Matlab. The command Matlab utilizes in conveniently called limit. Type help limit to get more information. Basically, all you have to do to calculate a limit is first identify your unknown x by using the syms command. Then you can ask Matlab to calculate the limit:

syms x
limit(x^2+x-1,x,0)
 
ans =
 
-1
 

The first input to limit is the function, the second input is the variable, and finally the third variable is where you want the limit to approach. Notice if you have a function defined symbolically, then you can just substitute that for the first input. Then, you have to update the rest of the inputs. For example:

syms X
f = 1./X
limit(f,X,0)
 
f =
 
1/X
 
 
ans =
 
NaN
 

Of course the solution to the limit of f(x) = 1/x as x approaches 0 is not a number (NaN) since the solution blows up as x gets closer and closer to 0. That's it! Have fun playing with limits.