# MATLAB

## Contents

## About

**MATLAB** (**mat**rix **lab**oratory) is a commerical software package which represents a numerical computing environment, high level programming language and visualization package. Matlab was developed by Mathworks and costs on the order of ~**$100** for a student licence, or **$1900** for a single commercial licence *(updated Dec 2012, version 8 / R2012v)*. Among its features, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, and Fortran.

I haven't personally used MATLAB much yet, but here I've collected some videos and what few things that I have learnt in MATLAB. Although hideously expensive, I do regret not learning to use it earlier, since suddenly in 2012 I've been told to use it.

### Make a shortcut to Matlab

To make a shortcut on your Terminal, edit your profile file:

pico ~/.bashrc # then add this line: alias matlab="/usr/local/MATLAB/R2012b/bin/matlab"

After your next restart you can just type "**matlab**" to launch it.

## Install Plugin

### CVX

CVX is a Matlab-based modeling system for convex optimization.

Download from here Unpack and copy to:

/usr/local/MATLAB/plugins

Once matlab is open copy this:

cd /usr/local/MATLAB/plugins/cvs cvx_setup

#### CVX Examples

```
cvx_begin
variables x1 x2
minimize(x1 + x2)
subject to
2*x1 + x2 >= 1
x1 + 3*x2 >= 1
x1 >= 0
x2 >= 0
cvx_end
% PROBLEM EXTRA EXC 3.2 / EX 4.1 ANSWERS:
% (a) minimize(x1 + x2) --> x1=0.4, x2=0.2
% (b) minimize(-x1 - x2) --> x1=3.9088e-08, x2=1.0
% (c) minimize(x1) --> x1=6.0507e-11, x2=9.6117
% (d) minimize(max(x1,x2)) --> x1=0.3333, x2=0.3333
% (d) minimize(x1^2 + 9*(x2^2)) --> x1=0.5, x2=0.1667
A = [-1, 0.4, 0.8; 1, 0, 0; 0, 1, 0];
b = [1; 0; 0.3];
xdes = [7; 2; -6];
N = 30;
x0 = [0; 0; 0];
```

```
cvx_begin
variables x(3, N+1) umid(N) uneg(N) upos(N)
minimize(norm(umid,1)+2*norm(upos,1)+2*norm(uneg,1))
subject to
umid >= -1
umid <= 1
upos >= 0
uneg <= 0
for t = 1:N
x(:, t+1) == A*x(:,t) + b*(umid(t)+uneg(t)+upos(t))
end
x(:,1) == x0
x(:,N+1) == xdes
cvx_end
```

## Keep Files

cd /usr/local/google/home/anoske/Documents/MATLAB