English | Español

Try our Free Online Math Solver!

Online Math Solver

 

 

 

 

 

 

 

 
 
 
 
 
 
 
 
 

 

 

 
 
 
 
 
 
 
 
 

Please use this form if you would like
to have this math solver on your website,
free of charge.


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
myvars.mat.

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

MATLAB follows a C like syntax . For example, the equality symbol `=' is used for assignment while `=='
must be used to test equality. The matrix is the fundamental data structure in MATLAB.

2.1 Entering variables
NUMBERS
< name-of-the-variable > = < value >
e.g.:

>> x = 0.65 enter

makes that MATLAB assigns the value 0:65 to the variable x.
MATLAB confirms :
x =

0.6500

>>

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

or

>> a = [ 0 1 2 enter
3 4 5 enter
6 7 8 ] enter

In both cases, MATLAB answers :

a =

0 1 2
3 4 5
6 7 8

2.2 The output

The content of a variable can be gotten just by typing in the name of the variable, followed by pressing the
enter
key.
e.g.:

>> x enter

MATLAB answers :

x =

0.6500

This is the standard output format of MATLAB. To obtain the scientific notation, you switch formats as
follows

>> format short e enter

After typing

>> x enter

MATLAB answers then with:

x =

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
returns

To transpose a matrix, you type an accent after the matrix.
e.g.: >> b = a' enter
returns

b =

0 3 6
1 4 7
2 5 8

Prev Next