= MATLAB - PowerPoint PPT Presentation

About This Presentation
Title:

= MATLAB

Description:

Mathematics + Laboratory = MATLAB = + Civil Engineering Dan Ophir, Ph.D. Cell.: 052-551359 e-Mail: comp_ophir_at_yahoo.com Requirements Students Files Conventions Mode ... – PowerPoint PPT presentation

Number of Views:143
Avg rating:3.0/5.0
Slides: 40
Provided by: BARUH
Learn more at: https://www.oocities.org
Category:

less

Transcript and Presenter's Notes

Title: = MATLAB


1
MATLAB
Mathematics Laboratory


MATLAB
Civil Engineering
Dan Ophir, Ph.D. Cell. 052-551359 e-Mail
comp_ophir_at_yahoo.com
2
Requirements
  • Tests
  • Intermediate,
  • Final.

75 Lectures 25 Exercises
Note Tests Exercises
Exercises in diskettes 1. .rtf format
(Office) 2. .m, .mdl, .fig (Matlab)
3
Students
8
7
6
5
4
3
2
1
4
Files
Users
  1. .m --- Script
  2. .mat --- Workspace
  3. .mdl --- Block program Model (Simulink)

5
Conventions
  1. gt - pressing on a menu, sub-menu, button
  2. blue link
  3. red a reserved word.

6
Mode of Interaction
Interactive Batch Script Program
Interpreter Compiler
7
MATLAB - Potential
Type Demo
8
Demo
MATLABgtMatricesgtgraphs and matrices MATLABgtNumeric
sgt2D-solutions MATLABgtNumericsgtCommand line
demosgtRun Command line demos gtfunction
plot MATLABgtVisualizationgt3D plots of comples
functionsgtRun 3D plots ofgt Cube root
9
Demo (2-cont.)
MATLABgtLanguage/Graphicsgt3d surface plotsgt Run 3D
surface plotsgtcolor map
10
Work Environment
Files
Work- Space
Desktop
Windows
11
Windows
  • Systems
  • Commands (history)
  • Variables
  • Help Window
  • Launch Pad
  • Workspace (variables)
  • Array Editor
  • Users
  • Script .m
  • Module .mdl
  • Figure .fig

12
Getting Starting
MATLAB Command Window
  • First commands
  • helpwin list of all .m files (scripts) included
    in the path (described in a help window) gt tips
    (gtSee also, gtBack, gtForward)
  • 2. help - a help in the command window.
  • 3. help debug a help of special topics or
    command.
  • lookfor conversion
  • which fprintf

13
Interactive Calculation
Command window x5 yx2 disp(y)
files .mat for workspace saving. MATLAB.mat
default file name
use save / load to treat with workspace file
who the local variables values whos the local
variables data structure
14
M-File Editor/Debugger window
Input
1. Command window setpath 2. Command window
open fibonaci.m file 3. Command window fibonaci
Output
1. Command window Fibonacci series 2. Figure No.
1
15
Fibonnacci
1 1 2 3 5 8 13 21
Converges to the golden ratio.
AB CB CB AC
A
B
C
16
Golden Ratio
Parthenon
17
Simulink window
Modeling Programming
  • First step
  • menufilegtnewgtmodel
  • or gtopengtbrowsing .mdl
  • gives the model specifications.
  • 3) model - icon
  • Second step
  • menu filegtopen
  • Browsing for .mdl
  • Third step (Integral window)
  • menu simulationgtstart
  • Input Integration windindows

C\MATLAB_5\my_examples\mdl\MDL\Simple\INTEGRAL.MD
L
18
MATLAB as a Language
Language Syntax, Semantics
19
Language Components
script function f(a,b) command
xy5 variable myBook_1 operator
constant 3.27 special symbol , ( )
20
Operations (operators)
operation symbol example
Addition 32
Subtraction - 54.4 25.3
Multiplication 3.15 6
Division / or \ 23.4/8
Exponentiation 34
helpwingtmatlab\opsgt
21
Variables
  • Naming rules
  • letters, digits, _
  • Case sensitive
  • Starting with a letter

Reserved World List (17) for end if while
function return elseif case otherwise switch
continue else try catch global persistent break
22
MATLAB specialvariables
Special Variables
23
Control Flow keywords
if - Conditionally execute
statements. else - IF statement
condition. elseif - IF statement
condition. end - Terminate scope of
FOR, WHILE, SWITCH and IF statements. for
- Repeat statements a specific number of
times. while - Repeat statements an
indefinite number of times. break -
Terminate execution of WHILE or FOR loop.
helpgtmanualgtcontrol flow helpgtelse
24
Functions Library
Trigonometric sin, cot Exponential log, exp,
, sqrt Complex conj, real Rounding and
remainder fix, floor, mod Coordinate
Transformation carth2sph,pol2cart Number
Theoretic factor, isprime, gcd Specialized
besselj, legendre
helpwingt matlab\elfun (topics elem. func) gt tan
25
Function Syntax
function list of output arguments name
(input-arg.) commands
Example function mean avg(x,n)
mean sum(x)/n
26
Command
Command collection of the following
entities variables, constants, calling
functions, keywords (reserved words) and
operators.
Examples x2310sin(0.3)
x
27
Program
Program A collection of commands with some
significance.
gtgt fibonnaci - sequence gtgt b(1)1 b(2)1 gtgt
for I35, b(I)b(I-1)b(I-2)
end gtgt b gtgt who
28
Example FOR, matrix
Output 2 3 4 5 3 4
5 6 4 5 6 7 5 6
7 8 6 7 8 9
Command gtgt for i15, for j14,
a(i,j)ij end
end gtgt a
basewords loop, matrix, index operators gtgt ,
()
column
row
29
Simple for, if
Code
Output
for I15 I end
1 2 3 4 5
I1 J2 X5 X6 if x5 I else J end

1 2
30
FAQ
Frequently Asked Questions ????? ??????

gtgt If for
Previous command
31
Language Manual
MANUAL.M
MANUAL.M
help manual
32
Script, Program, Function
Script, Program, Function A collection of
commands enclosed between two special commands
(module) and having a special task.
33
Exercise 1(list)
Choose 8 Reserved words and explain their
function in MATLAB and give examples of their
usage. Use the help features of MATLAB and the
manual.m file.
Choose 5 operators not given in the lecture and
explain their function
34
Exercise 2 (Pitagoras)
Input Two perpendicular sides a,b of a
right-angled triangle, Output The length of the
opposite side c. Do To write commands to compute
c.
c2 a2 b2
c
b
a
35
Simple Script Sum_Arr
1. a1 2 3 2. n3 3. function fsum(a,n) 4.
Computing the sum of the elements of an
array 5. sum10 6. for i1n, 7.
sum1sum1a(i) 8. end 9. fsum1 10.
ssprintf('sumd',sum1) 11. disp(s)
36
Fibonacci Script (recursive)
1. fibonaci.m (recusive algorithm) 2. A script
to calculate Fibonacci numbers 3. first
described by Leonardo of Pisa 4. f1 1 n1 5.
while f(n) f(n1) lt100 6. f(n2)f(n)f(n1)
7. nn1 8. end  
37
Exercise 3 (primes)
  1. Write a script/function myPrime to print all the
    prime numbers less than n
  2. Take n100.
  3. Compare the results with those received by using
    the MATLAB original function.

38
Line 2D
39
Exercise 4 Triangle
Draw (in the .m file) a triangle ,whose vertices
are at the points (5,5), (0,10), (10,10)
???? (???? .m) ????? ????????? ??????? ?????
(5,5),(0,10),(10,10)
Write a Comment
User Comments (0)
About PowerShow.com