Try our Free Online Math Solver!
Introduction to Symbolic Computation
1 The MATLAB environment
MATLAB is a software program that allows you to compute
interactively with matrices. If you want to know
for instance the product of a matrix a with a matrix b, then you just type in a * b and the result appears
immediately on screen. MATLAB has a wide range of functions to compute the determinant, inverse, LU-
decomposition, eigenvalues, etc.
While working with MATLAB you get on your screen always a
prompt. This is >>. This means that
MATLAB is ready to accept commands. If you press the enter key, the command gets executed.
Unless you finish your command with a semicolon (`;'),
MATLAB displays the result on screen. To copy
the output also to a file, you can invoke the command diary. For example,
>> diary('h : \nsession:txt') enter
will cause MATLAB to copy all user input and output to the
file h:\nsession.txt. The diary o® command
suspends the output to the file, whereas diary on turns it back on.
The command who displays the list all variables currently
in use. With clear you deallocate memory
space for those variables . If you want to use some or all of the variables with their values in a later MATLAB
session you can save the workspace variables with the command save('h:\ nmyvars') which creates the binary
MAT-file named myvars.mat. With load('h:\ nmyvars'), the workspace variables are loaded from the file
Make sure you understand the difference between the file
produced by diary and the file made by save!
With diary we create a human readable text file, with save we make a binary mat-file.
MATLAB records the commands you typed in. You can scroll
through the list of executed commands
with the arrow keys ↑ and ↓. The arrows ← and → enable to go to the location in the command where
edits are necessary. This is convenient to correct type errors in a command, or if you need to execute lots of
slightly different versions of the same instruction.
MATLAB has online help facilities. The command help
displays information in the current window,
helpwin opens a new window, helpdesk launches your internet browser.
2 A short introduction to MATLAB
2.1 Entering variables
NUMBERS < name-of-the-variable > = < value >
>> x = 0.65 enter
makes that MATLAB assigns the value 0:65 to the variable
MATLAB confirms :
MATRICES These are defined row-wise. A square bracket [
means to MATLAB that you wish to enter a
matrix. The input of a matrix is terminated by a ]. You can enter a matrix in two ways .
For instance, you want
then you either type
>> a = [ 0 1 2 ; 3 4 5 ; 6 7 8 ] enter
>> a = [ 0 1 2 enter
3 4 5 enter
6 7 8 ] enter
In both cases, MATLAB answers :
0 1 2
3 4 5
6 7 8
2.2 The output
>> x enter
MATLAB answers :
This is the standard output format of MATLAB. To obtain
the scientific notation, you switch formats as
>> format short e enter
>> x enter
MATLAB answers then with:
If you replace in the format-commands short by long, you
see more decimal places .
To return back to the standard output format, you type
>> format short enter
2.3 Selecting en transposing
You can select elements from a matrix :
a(i, j) returns the element on the i-th row and j-th column.
a(i, :) returns the entire i-th row of a.
a(:, j) returns the entire j-th column of a.
a(i : j, k : l) returns the matrix a(i… j; k … l).
e.g.: >> m = a(1 : 2, 2 : 3) enter
To transpose a matrix, you type an accent after the
e.g.: >> b = a' enter
0 3 6
1 4 7
2 5 8