Miscillaneous Matlab Goodies!

 

 

On ezplot and fplot:

These are two Matlab commands that plot symbolic functions. For fplot the user must specify a vector [xmin xmax], and it is optional for ezplot. The standard way of use (with versions 4.0 and 5.5) is:

 

ezplot('sin(x)')  

 

  

 

or

 

fplot('sin(x)',[-5 +5])  

 

  

 

ezplot sin(x)   or ezplot(y)  also work if we first define y = 'sin(x)'; however, ezplot y does not work.

 

Defining functions symbolically:

Older version of Matlab Symbolic Toolbox (e.g., v.4.0) restricted the definition of symbolic functions according to, e.g., :

 

y='tanh(x) + x^2'  

 

y =

tanh(x) + x^2  

 

This also works with newer versions. However, newer versions (say v5.0) also allows:

 

syms x  

y = tanh(x) + x^2  

 

One can use findsym(y,1)to find the Matlab assumed variable in expressions containing more than one symbol. E.g.,

 

findsym('a*c+5',1)  returns c as the variable (since c is closer to the default variable 'x').

 

 

funtool:

This is a nice Matlab command that open a user friendly interface and allows for symbolic functions (two functions of one variable each) to be plotted, differentiated, composed, etc.) funtool work from within a Matlab window.

 

 

Base Conversions:

 

dec2bin(45)  

 

ans =

101101  

 

dec2hex(45)  

 

ans =

2D  

 

bin2dec('10010')  

 

ans =

    18  

 

hex2dec('E6')  

 

ans =

   230  

 

 

Computing factorial and combinations:

There is no build-in function for factorial(n) in Matlab (e.g., 4! does not work). However, one can use:

 

prod(1:4)  

 

ans =

    24  

 

prod(1:0)  

 

ans =

     1  

 

or gamma(n+1) for n!

 

gamma(4+1)  

 

ans =

    24  

 

Example: Find the combination C(5,3):

 

C=prod(1:5)/(prod(1:5-3)*prod(1:3))  

 

C =

    10  

 

 

Special Variables:

pi  

 

ans =

    3.1416  

 

Infinity: inf

 

eps  

 

ans =

  2.2204e-016  

 

i  

 

ans =

        0+ 1.0000i  

 

e.g.,

 

e=exp(1)  

 

e =

    2.7183