Prev Up
Go backward to 2.5 Other Miscellaneous MATLAB Commands
Go up to 2 Starting with MATLAB

Some Examples

Here are a few examples of using MATLAB, showing some important details (like how MATLAB deals uses i and j to represent one of the square roots of -1):

  1. >> conj( [1+7i, 2-6j])
    ans =
       1.0000 - 7.0000i   2.0000 + 6.0000j
    
  2. >> w = [-1 : 1 : 2]
    w =
        -1     0     1     2
    >> log(w)
    
    Warning: Log of zero.
    ans =
       0 + 3.1416i     -Inf             0        0.6931
    
     
  3. >> x = [ -3 : 0.2 : 3 ];
    >> y = exp( -x .* x );   %OR:   y = exp( - x .^ 2 );
    >> plot(x, y);
    >> title('Graph of  y=exp(-x^2)');
    >> xlabel('x-values'); ylabel('y-values');
    
     

    The final graph is shown in Figure 2.5.

Graph of y=exp(-x2).
 

Notice that the top of the graph is not very smooth. What can be done to make the graph smoother? It would also be good to have the graph not touching the top border. Have a look at the help for the function axis.

 


Peter Dunn

Prev Up