W A T K I N S - J O H N S O N C O M P A N Y Semiconductor Equipment Group - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

W A T K I N S - J O H N S O N C O M P A N Y Semiconductor Equipment Group

Description:

... T3 = 1.3270 T4 = asind(.497) T4 = 29.8017 T5 = acosd(0.629) T5 = 51.0236 T6 = atand(1.73) T6 = 59.9706 Printing From Command Window ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 52
Provided by: WATKINSJ6
Category:

less

Transcript and Presenter's Notes

Title: W A T K I N S - J O H N S O N C O M P A N Y Semiconductor Equipment Group


1
Engr/Math/Physics 25
Chp1 MATLABOverView Part-1
Bruce Mayer, PE Licensed Electrical Mechanical
EngineerBMayer_at_ChabotCollege.edu
2
Learning Goals
  • Turn On MATLAB and use as a calculator
  • Create Basic Cartesian Plots
  • Write and Save simple Script Program-files
  • Execute Conditional Statements
  • IF, THEN, ELSE, gt, lt, gt, etc.
  • Execute Loop Statements
  • FOR WHILE

3
MATLAB Environment
  • TWO Interaction Modes
  • INTERACTIVE
  • Type in the COMMAND WINDOW
  • Often Called a Command-Window Session
  • Interaction is NOT Saved to Disk
  • Commands (NOT results) Stored in Command
    History Buffer Window
  • STORED ? Two Types
  • SCRIPT Files
  • FUNCTION Files

4
Typing Occurs Here
5
Example Cmd Window Session
gtgt Use MATLAB As Calculator gtgt 1719 ans
323 gtgt 77/19 -4.3 ans -0.2474 gtgt 64(1/3)
320.2 ans 6
gtgt (711)2.5 ans 45 gtgt L 14.4 L
14.4000 gtgt W 13.3 W 13.3000 gtgt Area
LW Area 191.5200
Time For Live Demo
6
Script/Function File Editor
7
Script Function Files (m-files)
  • SCRIPTS and FUNCTIONS in MATLAB are stored in
    text files that end with the extension .m
  • These files are called m-files
  • SCRIPTS (a.k.a. programs)
  • Scripts files are useful for automating tasks
    that may need to be repeated.
  • They have no input/output parameters
  • They can (but probably shouldnt) share variables
    with the command workspace

8
Script Function Files (m-files)
  • SCRIPTS (cont.)
  • Scripts are sequences of interactive statements
    stored in a file
  • i.e., They look liked Stored versions of Command
    Window Sessions
  • FUNCTIONS (a.k.a. subroutines)
  • Function m-files are MATLAB subprograms analogous
    to FORTRAN Subroutines, or C functions
  • They communicate with the command window and
    other functions via a list of INPUT and OUTPUT
    PARAMETERS

9
Script Function Files (m-files)
  • FUNCTIONS (cont.)
  • Functions COMMUNICATE with the COMMAND WINDOW and
    other m-files via a list of input and output
    variables
  • LOCAL variables are variables defined INSIDE the
    function
  • They only can be used inside the function in
    which they reside.
  • The number of output parameters used when a
    function is called must match the number of
    outputs that function is expected to return

10
Entering Commands Expressions
  • MATLAB retains your previous keystrokes.
  • Use the up-arrow (?) key to scroll back through
    the commands.
  • Press the key (?) once to see the previous entry,
    and so on.
  • Use the down-arrow (?) key to scroll forward.
  • Edit a line using the left (?) right (?) arrow
    keys the Backspace key, and the Delete key.
  • Press the Enter key to execute the command

11
Arithmetic Scalar Operations
Symbol Operation MATLAB
exponentiation ab ab
multiplication ab ab
/ right division a/b a/b
\ left division b/a a\b
addition a b a b
- subtraction a - b a - b
  • LEFT-Division A\b read from Right-to-Left as b
    divided by AC

12
Math Op Precedence (PEMDAS)
Precedence Operation
First Parentheses, evaluated starting with the
innermost pair. Second Exponentiation,
evaluated from left to right. Third Multiplicatio
n and Division with EQUAL precedence, evaluated
from left to right. Fourth Addition and
Subtraction with EQUAL precedence, evaluated
from left to right.
13
Precedence Examples
gtgt 835 ans 23 gtgt 8 (35) ans
23 gtgt(8 3)5 ans 55
gtgt42128/42 ans 0 gtgt42128/(42) ans
3
4
1
14
Precedence Examples cont.
gtgt 342 5 ans 53 gtgt(34)2 5 ans
149
gtgt27(1/3) 320.2 ans 5 gtgt271/3
320.2 ans 11
3
48
9
144
15
? Assignment Operator
  • Typing x 3 ASSIGNS the value 3 to the variable
    x.
  • We can then type x x 2. This assigns the
    value 3 2 5 to x. But in algebra this
    implies that 0 2.
  • In algebra we can write x2 20, but in MATLAB
    we cannot.
  • In MATLAB the LEFT side of the operator MUST be
    a SINGLE variable.
  • The Right side must be a computable value

16
Work Session Commands
Command Description
clc Clears the Command window
clear Removes all variables from memory
clear v1 v2 Removes the variables v1 and v2 from memory
exist(var) Determines if a file or variable exists having the name var
quit Stops MATLAB
17
Work Session Commands cont.1
Command Description
who Lists the variables currently in memory
whos Lists the current variables and sizes, and indicates if they have imaginary parts.
(Colon) Generates an array having regularly spaced elements
, (Comma) Separates elements of an array
(Semicolon) Suppresses screen printing also denotes a new row in an array
(Ellipsis) Continues a line
18
whos on First???
19
Special VARS consts
Command Description
ans Temporary variable containing the most recent answer
eps Specifies the accuracy of floating point precision
i,j The imaginary unit ?(-1)
Inf Infinity (unbounded magnitude)
NaN Indicates an undefined numerical result a.k.a., Not a Number
pi The number pi (3.14159...)
  • NaN returns the IEEE arithmetic representation
    for Not-a-Number (NaN). These result from
    operations which have undefined numerical
    results. e.g., try Q 0/0

20
The Complex Plane
Im (i or j)
Re
21
Complex-Number Operations
  • The number c1 1 2i is entered as c1 12i
    or c1 1-2j
  • An Asterisk is NOT needed between i or j and a
    NUMBER, although it is required with a VARIABLE,
    such as c2 5 ic1.
  • Be careful. The expressions
  • y 7/2i and x 7/2j
  • give two DIFFERENT results
  • y (7/2)i 3.5i
  • and x 7/(2j) 3.5j

22
Complex Arithmetic
gtgt Im_Pwr Z13.84 Im_Pwr -1.6858e004
-2.5886e004i gtgt e_to_Z exp(Z2) e_to_Z
6.8518e006 -2.3163e007i
gtgt Log_Z log10(Z2) Log_Z 1.2485 0.1242i
gtgt Ln_Z log(Z1) Ln_Z 2.6922 1.0769i
23
Special VARS consts
Command Description
format short Four decimal digits (the default) 13.6745
format long 16 digits 17.27484029463547
format short e Five digits (four decimals) plus exponent 6.3792e03
format long e 16 digits (15 decimals) plus exponent 6.379243784781294e04
24
Discrete Math Funtions
Command Description
factor(n) Returns a row vector containing the prime factors of n.
gcd(m,n) Finds the Greatest Common Divisor/Factor of m n
lcm(m,n) Finds the Least Common Multiple for m n
factorial(n) Returns the factorial of n i.e., returns n! 123(n-2)(n-1)n
primes(n) Finds all prime numbers less than n
isprime(n) Determines if n is a prime number
25
Discrete Math Examples
factor777 factor(777) factor777 3
7 37 GCF gcd(1001, 1105) GCF
13 F7 factorial(7) F7 5040
P93 primes(93) P93 Columns 1 through 12
2 3 5 7 11 13 17 19
23 29 31 37 Columns 13 through 24
41 43 47 53 59 61 67 71
73 79 83 89
26
Arrays
  • An ARRAY is an ORDERED SET of Numbers of with n
    DIMENSIONS
  • A regular Number (a SCALAR) is an Array of
    Dimension ZERO
  • A VECTOR is a 1-Dim Array
  • A MATRIX is an ARRAY of Dim ? 2with
    specialproperties

27
Arrays in MATLAB
  • The numbers 0, 0.1, 0.2, , 10 can be assigned to
    the array variable u by typing
  • u 00.110
  • To compute w 5 sin u for u 0, 0.1, 0.2, 0.3,
    0.4,, 10, the command session is
  • gtgtu 00.110
  • gtgtw 5sin(u)
  • The single line, w 5sin(u), computed the
    formula, w 5 sin(u), 101 times.

28
Array Index
  • gtgtu(7)
  • ans
  • 0.6000
  • gtgtw(7)
  • ans
  • 2.8232
  • Use the LENGTH function to determine how many
    values are in an array.
  • gtgtm length(w)
  • m
  • 101

29
Polynomial Roots
  • MATLAB has a Way-Cool Polynomial Root Finder
  • Find the roots of x3 - 7x2 40x - 34 0
  • gtgta 1,-7,40,-34
  • gtgtroots(a)
  • ans
  • 3.0000 5.000i
  • 3.0000 - 5.000i
  • 1.0000
  • The roots are x 1 and x 3 5i

30
5th Order Polynomial
  • Find the roots of the 5th Order function

gtgt r5 1,-9,35,-65,64,-26 gtgt roots(r5) ans
3.0000 2.0000i 3.0000 - 2.0000i 1.0000
1.0000i 1.0000 - 1.0000i 1.0000
  • The roots of g(y)
  • y1,2 3 2j
  • y3,4 1 j
  • y5 1

31
Common Math Functions
Fcn MATLAB Fcn MATLAB
ex exp(x) sin x sin(x)
vx sqrt(x) tan x tan(x)
ln x log(x) cos-1 x acos(x)
log10 x log10(x) sin-1 x asin(x)
cos x cos(x) tan-1 x atan(x)
  • Note that MATLAB Trig functions Operate on
    RADIANS
  • Convert using Ratio ?-rads per 180

32
The d Trig Comands for Degrees
gtgt T1 sind(77) T1 0.9744 gtgt T2
cosd(19) T2 0.9455 gtgt T3 tand(53) T3
1.3270
gtgt T4 asind(.497) T4 29.8017 gtgt T5
acosd(0.629) T5 51.0236 gtgt T6
atand(1.73) T6 59.9706
33
Printing From Command Window - 1
TexttoPrint
  • Note MATLAB Comments Start with the Sign

34
Printing From Command Window - 2
SELECTText toPrint
35
Printing From Command Window - 3
  • Send to printer from Print Dialog Box
  • Caveat
  • In a COMMAND WINDOW session once you Hit Enter
    (?) you can NOT Go back to Edit the Text
  • Can Save your command sequence as an m-file SCRIPT

36
Alternative Cmd Window Printing
  • Perform MATLAB Operation
  • Select Desired Text
  • COPY text to the Windows Paste Buffer
  • Open Text application
  • MSWord, WordPad, NotePad, etc.
  • PASTE the MATLAB Text Into the Text Processor
  • Print from the Text Processor as Usual

37
DIARY Function to Record Cmnds
  • Keeping a Session Log ? The diary Function
  • The diary function creates a copy of your session
    in MATLAB on a disk file, including keyboard
    input and system responses, but excluding
    graphics. You can view and edit the resulting
    text file using any text editor, such as the
    MATLAB Editor. To create a file on your disk
    called sept23.out that contains all the functions
    you enter, as well as output from MATLAB, enter
  • diary('sept23.out')
  • To stop recording the session, use
  • diary('off')
  • To view the file, run
  • edit('sept23.out')

38
Command Execution Hierarchy
  • When you type problem1
  • MATLAB first checks to see if problem1 is a
    variable and if so, displays its value.
  • If not, MATLAB then checks to see if problem1 is
    one of its own commands, and executes it if it
    is.
  • If not, MATLAB then looks in the current
    directory for a file named problem1.m and
    executes problem1 if it finds it.
  • If not, MATLAB then searches the directories in
    its search path, in order, for problem1.m and
    then executes it if found.

39
System, Directory, File Cmnds
Command Description
addpath dirname Adds the directory dirname to the search path.
cd dirname Changes the current directory to dirname
dir Lists all files in the current directory
dir dirname Lists all the files in the directory dirname
path Displays the MATLAB search path
pathtool Starts the Set Path tool
  • HINT Consider putting ALL your m-files in ONE
    Folder/Directory

40
System, Directory, File Cmnds
Command Description
pwd Displays the current directory
cd dirname Changes the current directory to dirname
rmpath dirname Removes the directory dirname from the search path.
what Lists the MATLAB-specific files found in the current working directory. Most data files and other non-MATLAB files are not listed. Use dir to get a list of all files
what dirname Lists the MATLAB-specific files in directory dirname
41
Plotting with MATLAB
  • Plot over 573

42
MATLAB Plotting Commands
Command Description
plot(x,y) Generates a plot of the array y versus the array x on rectilinear axes
title(text) Puts text in a title at the top of the plot
xlabel(text) Adds a text label to the horizontal axis (the abscissa).
ylabel(text) Adds a text label to the vertical axis (the ordinate).
grid Puts grid lines on the plot
gtext(text) Enables placement of text with the mouse
43
  • DeskTop Recovery
  • To UNSCRAMBLE Desktop

44
DeskTop Recovery
  • To UNSCRAMBLE Desktop

45
Example Problem 1-21
  • Plot This Function

Time For Live Demo
  • Where
  • T ? Temperature (C)
  • t ? time (minutes)
  • For 1 ? t ? 3

46
All Done for Today
P1.30TutorialNextMeeting
47
Engr/Math/Physics 25
Appendix
Bruce Mayer, PE Licensed Electrical Mechanical
EngineerBMayer_at_ChabotCollege.edu
48
Example Demo Session
gtgt Use MATLAB As Calculator gtgt 1719 ans
323 gtgt 77/19 -4.3 ans -0.2474 gtgt 64(1/3)
320.2 ans 6
gtgt (711)2.5 ans 45 gtgt L 14.4 L
14.4000 gtgt W 13.3 W 13.3000 gtgt Area
LW Area 191.5200
49
Prob 1-21 Command Script
  • From the Command Window

gtgt t 10.023 gtgt T 6log(t) -
7exp(0.2t) gtgt plot(t,T), xlabel('time
(min)'),ylabel('Temperature (C)'),
title('Problem 1-21'), grid
50
Prob 1-22 Plot
51
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com