Professional Documents
Culture Documents
Introduction course
Fanilo RAMASOMANANA ramasoma@unistra.fr
MATLAB - Introduction course
What is MATLAB?
MATLAB is a commercial software of interactive calculus. It makes it possible to carry out numerical simulations based on algorithms of numerical analysis. It can thus be used for solving numerical problems for the approximate resolution of differential equations, partial differential equations, linear and nonlinear systems, or scientific and engineering graphics, etc and to write programs in a lower level language. MATLAB provides a block diagram tool for modeling and simulating dynamical systems, including signal processing, controls, communications, and other complex systems ranging from engineering and mathematics to chemistry, biology, and economics.
Objectives
The objective of this MATLAB's course is double:
the knowledge of this software is essential because it is more and more used for calculus in industries and banks, the knowledge of algorithms existing in the software and to test new algorithms.
Introduction Chapter 1:
This chapter provides a brief introduction to starting and quitting MATLAB, and the tools and functions that help you to work with MATLAB variables and files.
Quitting MATLAB:
To end your MATLAB session, select Exit MATLAB from the File menu in the desktop, or type quit in the Command Window.
MATLAB Desktop
MATLAB Desktop
You can change the way your desktop looks by opening, closing, moving, and resizing the tools in it. You can also move tools outside of the desktop or return them back inside the desktop.
When you start MATLAB, the MATLAB desktop appears, containing tools for managing files, variables, and applications associated with MATLAB.
The first time MATLAB starts, the desktop appears as shown in the following illustration.
Desktop Tools
This section provides an introduction to MATLABs desktop tools. The tools are: Command Window Command History Help Browser Current Directory Workspace Array Editor Create M-Files
Desktop tools
To create M-files, select New M-files from the File menu, which allow to write programs and run MATLAB functions. We can save the new algorithms in a any directory in a file called a M-file, which has a .m extension.
If you just need to view the contents of an M-file, you can display it in the Command Window by using the name of the function or running this function.
Chapter 2
Operators for numbers
Special functions for numbers Operators for vectors Special functions for vectors Operators for matrices Special functions for matrices + *
/ ^
Division Power
Special functions:
pi i Inf NaN abs 3.1415 Imaginary unit Infinity Not a number Absolute value sqrt Square root log Logarithm exp Exponentiel sign Signe of the number (=1 if positif and 0 if negatif)
MATLAB - Introduction course
angle the phase angle of the complex number real imag conj the real part of the complex number the imaginary part of the complex number the conjugate of the complex number
For a nonunit spacing, we can specify an increment. For example: X=100:-7:50 or X=0:pi/4:pi
Chapter 3 if
The if statement evaluates a logical expression and executes a group of statements when the expression is true. The optional elseif and else keywords provide for the execution of alternate groups of statements. An end keyword, which matches the if, terminates the last group of statements. The groups of statements are delineated by the four keywords no braces or brackets are involved.
Chapter 3 if (example):
if a < 0 a = a+1; elseif a == 0 a=0; else a=a; end
Chapter 3 for
The for loop repeats a group of statements a fixed, predetermined number of times. A matching end delineates the loop.
Chapter 3
The while loop repeats a group of statements an indefinite number of times under control of a logical conditions. A matching end delineates the loop.