MATLAB
Essentials for Engineers and Scientists
Introduction
Introduction
MATLAB's Power of Computational Mathematics
(Matrix Laboratory)
Dealing with Matrices and Arrays
2-D and 3-D Plotting and graphics
Linear Algebra
Algebraic Equations
Non-linear Functions
Statistics
Data Analysis
Calculus and Differential Equations
Numerical Calculations
Integration
Transforms
Curve Fitting
Various other special functions
Introduction
Features of MATLAB
It is a high-level language for numerical computation, visualization and
application development.
It also provides an interactive environment for iterative exploration,
design and problem solving.
It provides vast library of mathematical functions for linear algebra,
statistics, Fourier analysis, filtering, optimization, numerical integration
and solving ordinary differential equations.
It provides built-in graphics for visualizing data and tools for creating
custom plots.
MATLAB's programming interface gives development tools for improving
code quality maintainability and maximizing performance.
It provides tools for building applications with custom graphical interfaces.
It provides functions for integrating MATLAB based algorithms with
external applications and languages such as C, Java, .NET and Microsoft
Excel.
Uses of MATLAB
Signal Processing and Communications
Image and Video Processing
Control Systems
Test and Measurement
Computational Finance
Computational Biology
Bài tập về nhà
Cài MATLAB r2013 ++
On-line
Workspace
Current Folder
Command Window
History
To start from Windows,
double-click the MATLAB icon on your Windows desktop.
To quit:
Close MATLAB box
Type: quit or exit
Arithmetic Variable
>> 3-2 <Enter> >> x = 2; y = 3; <Enter>
>> 2*3 <Enter> >> z = x + y <Enter>
>> 1/2 <Enter>
>> 23 <Enter>
>> 2\11 <Enter>
Mathematical Function
>> pi <Enter>
>> sqrt(pi) <Enter>
>> whos <Enter>
>> clear pi <Enter>
General Function and command
>> whos <Enter>
>> date <Enter> >> sqrt(pi) <Enter>
>> clc <Enter> >> clear <Enter>
>> close <Enter> >> whos <Enter>
>> help <Enter>
MATLAB is case-sensitive.
Vector Plot
>> x = 0 : 10; <Enter> >> x = 0 : 0.1 : 10; <Enter>
>> y = sin(x); <Enter>
>> size(x) <Enter> >> plot(x,y), grid <Enter>
>> xlabel(’ x ’), ylabel(’ sin(x) ’) <Enter>
>> y = 2 .* x <Enter> >> whitebg(’y’) <Enter>
>> w = y ./ x <Enter>
>> z = sin(x) <Enter>
>> x = 1:0.1:10; <Enter>
>> z = tan(x); <Enter>
>> plot(x,z),axis([0 10 -10 10]) <Enter>
>> ezplot(’tan(x)’) <Enter>
Tab completion: Type the first few letters of a MATLAB name and then press Ta
Linear Eq.
x +2y = 4
2x −y = 3
Built-in Solve function
Matrix method
>> syms x y;
>> a = [1 2; 2 -1]; <Enter >
>> [x,y] = solve(x+2*y-4, 2*x - y-3) <Enter >
>> b = [4; 3]; <Enter >
>> whos <Enter >
>> x = a\b <Enter >
>> x = double(x), y=double(y) <Enter >
>> whos <Enter >
Exercise
Plot 2D
𝑦 =sin ( 𝑥 )
x = 0 - 4
𝑦 =sin ( 2 𝑥 )
𝑦 =sin ( 3 𝑥 )
Exercise 1.3 (text-book)
` Assign a value to the variable x on the command line, e.g.,x = 4 * pi^2.
What is the square root of x? What is the cosine of the square root of x?
Additional features
Magic square
Ex.: magic (4)
Meshgrid/Mesh/Surf
>> [x y ] = meshgrid(-8 : 0.5 : 8); <Enter>
>> r = sqrt(x.^2 + y.^2); <Enter>
>> z = sin(r) ./ r; <Enter> 1
>> mesh (z); <Enter> 0.5
-0.5
40
30 40
20 30
20
10 10
0 0
Tutorials and demos
Type: demo
Help – Publish and View
%%
% This is an example to illustrate how easy it is to create a document
% in the PUBLISH environment.
%
% (1) This is an illustration of a formula created with a LaTeX command:
%
%%
% $x^2+e^{\pi i}$
%
% (2) This is an illustration of how you can incorporate a MATLAB script
% in the document that is run when the Publish button below and to the
% right of View is clicked:
% Earth picture
load earth
image(X); colormap(map);
axis image
Exercise
Publish the following script -> e-learning
e−0.2x sin(x)
x {0, 6π}