Matlab???? From getstart.pdf - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Matlab???? From getstart.pdf

Description:

Title: PowerPoint Presentation Last modified by: Created Date: 1/1/1601 12:00:00 AM Document presentation format: Other titles – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 37
Provided by: mathHduE
Category:
Tags: getstart | matlab | pdf | sine

less

Transcript and Presenter's Notes

Title: Matlab???? From getstart.pdf


1
Matlab???? From getstart.pdf
  • Hangzhou Dianzi University
  • Science School
  • 2005?

2
????
  • ??
  • ????
  • ??
  • ?matlab??

3
MATLAB
??www.mathworks.com ???comp.soft-sys.matlab.
Math and computation Algorithm
development Modeling, simulation, and
prototyping Data analysis, exploration, and
visualization Scientific and engineering
graphics Application development, including
graphical user interface building
4
MATLAB
matrix laboratory. ??????array,no
t require dimensioning.
5
??????
Development Environment. The MATLAB Mathematical
Function Library. The MATLAB Language. Handle
Graphics. The MATLAB Application Program
Interface (API).
6
Development Environment.
This is the set of tools and facilities that help
you use MATLAB functions and files. Many of these
tools are graphical user interfaces. It includes
the MATLAB desktop and Command Window, a command
history, and browsers for viewing help, the
workspace, files, and the search path.
7
(No Transcript)
8
The MATLAB Mathematical Function Library.
This is a vast collection of computational algorit
hms ranging from elementary functions like sum,
sine, cosine, and complex arithmetic, to more
sophisticated functions like matrix inverse,
matrix eigenvalues, Bessel functions, and fast
Fourier transforms.
9
The MATLAB Language
This is a high-level matrix/array language with
control flow statements, functions, data
structures, input/output, and object-oriented
programming features. It allows both programming
in the small to rapidly create quick and dirty
throw-away programs, and programming in the
large to create complete large and complex
application programs.
10
The MATLAB Application Program Interface (API).
This is the MATLAB graphics system. It includes
high-level commands for two-dimensional and
three-dimensional data visualization, image
processing, animation, and presentation graphics.
It also includes low-level commands that allow
you to fully customize the appearance of graphics
as well as to build complete graphical user
interfaces on your MATLAB applications.
11
????
12
Flow Control
  • if ????
  • switch??
  • for??
  • while ??
  • continue??
  • break??

13
IF
if rem(n,2) 0 M odd_magic(n) elseif rem(n,4)
0 M single_even_magic(n) else M
double_even_magic(n) end
14
IF
a1 23 4
a1b4 if ab a3 else a4 end
if all(a())
if a
b 2 3 4 7 ab isequal(a,b)
15
IF
if agtb greater else if altb less
elseif ab equal else error(unepected
situation) end
isequal isempty all any
16
Switch and Case
switch (rem(n,4) 0) (rem(n,2)0) case 0
M odd_magic(n) case 1 M
single_even_magic(n) case 2 M
double_even_magic(n) otherwise error(This
is impossible) end
17
For
for n 332 r(n) rank(magic(n)) end r
for i1m for j1n H(i,j) 1/(ij)
end end
18
While
a0 fa -Inf b3 fbInf while b-agt epsb
x (ab)/2 fxx3-2x-5 if sign(fx)
sign(fa) ax fafx else
bxfbfx end end x
19
Continue
fid fopen(magic.m,r) count0 while
feof(fid) line fgetl(fid) if
isempty(line)strncmp(line,,1)
continue end count count 1 end
disp(sprintf(d lines,count))
20
Break
a0 fa -Inf b3 fbInf while b-agt epsb
x (ab)/2 fxx3-2x-5 if fx 0
break elseif sign(fx) sign(fa) ax
fafx else bxfbfx end end
21
Script
Investigate the rank of magic squares r
zeros(1,32) for n332 r(n)rank(magic(n))
end r bar(r)
?edit???????,????magicrank.m ?matlab??? gtgt
magicrank.m (gtgt????)
22
(No Transcript)
23
Function
function r rank(A,tol) RANK Matrix rank.
RANK(A) provides an estimate of the number of
linearly independent rows or columns of a
matrix A. RANK(A,tol) is the number of
singular values of A that are larger than
tol. RANK(A) uses the default tol
max(size(A)) norm(A) eps. s svd(A) if
nargin1 tol max(size(A)') max(s)
eps end r sum(s gt tol)
rank.m
??lookfor
help
s,tol,r?????
24
rank
help rank lookfor rank rank(A) r rank(A) r
rank(A,1.e-6)
25
Global Variables
function h falling(t) global GRAVITY h
1/2Gravityt.2
gtgtglobal GRAVITY gtgtGRAVITY 32 gtgty
falling((0.15))
26
Passing String Arguments to Functions
foo a b c
foo(a,b,c)
legend apples orange legh,objh
legend(apples,oranges)
27
Constructing string arguments in code
for d 131 s August int2str(d) .dat
load(s) code to process the contents of the
d-th file end
A0 6 1 6 2 16 -5 20 10 eig(A) eig
A ?
28
eval
for d 131 s load August int2str(d)
.dat load(s) code to process the
contents of the d-th file end
29
Vectorization and Preallocation
x .01 for k 11001 y(k) log10(x)
x x .01 end
x .01.0110 y log10(x)
r zeros(32,1) for n132
r(n)rank(magic(n)) end
30
Function Handles
function x plot_fhandle(fhandle,data)
plot(data,fevel(fhandle,data))
plot_fhandle(_at_sin, -pi0.01pi)
plot_fhandle(sin, -pi0.01pi)
31
Function Functions
  • Zero finding
  • Optimization
  • Quadrature
  • Ordinary differential equations

function y hupms(x) y 1./((x-.3).2
.01)1./((x-.9).2.04)-6
x 0.0021 y humps(x) plot(x,y)
32
(No Transcript)
33
Function Functions
p fminsearch(_at_humps,.5) Q
quad1(_at_humps,0,1) z fzero(_at_humps, .5)
34
(No Transcript)
35
close all rand('seed',.123456) NumberInside
0 PiEstimate zeros(500,1) for k1500 x
-12rand(100,1) y -12rand(100,1)
NumberInside NumberInside sum(x.2 y.2 lt
1) PiEstimate(k) (NumberInside/(k100))4
end plot(PiEstimate) title(sprintf('Monte
Carlo Estimate of Pi 5.3f',PiEstimate(500))) x
label('Hundreds of Trials')
36
Other data structures
  • Multidimensional arrays
  • Cell arrays
  • Characters and text
  • Structures
Write a Comment
User Comments (0)
About PowerShow.com