• Today's lecture
  explores these two areas as applied to Matlab 
References:        For Engineers (Ch. 1) 
                                                            User's
  Guide (Ch. 1, 3, 9) 
                                                            Mastering
  (Ch.. 2, 5, 10) 
16.1       Variables 
• Programs model
  some aspect of the real world 
data objects
  (variables) which the program employs & manipulates thus represent some
  object or concept in the real world 
• In Matlab a
  variable has 
-              name 
• an identifier (or
  handle) 
• selected to
  indicate what real world object it represents 
-              data type 
• what values can
  the variable have? 
• what operations
  can be performed upon it? 
• all Matlab
  variables have a default type (class) which is a vector of real numbers 
16.2       Identifiers 
• Names created by
  the programmer to represent various objects (quantities) in the program 
• Syntax: 
-              No white-space (e.g., class
  total is not valid) 
-              Must start with a letter (e.g.,
  k9 is valid, 2tango is not) 
-              Can be composed from letters,
  digits, & underscores (e.g., class_total is valid, class-total is not
  valid) 
-              Can have up to 31 characters
  (those beyond 31 are ignored) 
-              Is case sensitive (e.g.,
  highscore and highScore are two different variables) 
• Avoid pre-defined
  function and reserved words (e.g., "for", "mean" etc. as
  these replace the built-in functions) 
16.3       Meaningful Identifiers 
• Identifiers should
  communicate their purpose (meaning – what they represent) clearly and
  precisely without undue verbosity 
16.3.1    Some Examples 
s1                          vs. student1 
the_first_student_on_the_course  vs. first_student 
N, k, m, n                                           (OK
  for maths) 
student1 &
  student2        (try to avoid similar
  names) 
high_score          or highScore                       
(two conventions for
  composite ids) 
16.4       Weak Typing 
• Unlike many 3rd
  generation languages, Matlab is extremely weakly typed: 
- no declaration of
  variables before use 
- one major type of
  data (variable) with a few special cases & additions 
• by default
  everything is a vector (1-dimensional array) of real numbers 
• single values
  (scalars) simply a vector with a single element 
e.g. 
 | 
 
               single
  = 9.3;        % A vector with one  
                        % element 
                                                                                % i.e., a scalar 
                              countDown =
  10:-1:1;     % A vector:  
                             % 10, 9,…,1 
                              average =
  mean(values);  
                        % May be a scalar, 
                                                                     % vector or matrix 
16.5       Implications of Weak Typing 
• This approach has
  several advantages & dis-advantages: 
-              very powerful things may be
  expressed (& hence solved) very easily, but there is little
  "protection" 
16.5.1    Advantages 
• Shorter initial
  learning curve: can write useful programs nearly immediately 
• Implicit
  vectorisation (everything treated a a vector) leads to simpler and more
  intuitive programs 
16.5.2    Disadvantages 
• No protection for
  users from simple errors (e.g., typed results=x+y instead of result=x+y;) 
• Single statements
  become harder to understand (e.g., does average=mean(values); produce a
  scalar, vector or array?) 
• More difficult to
  closely match real-world objects 
16.6       Special (Built-in) Constants &
  Variables 
• Matlab has a
  number of built-in constants and variables 
Name    Description 
ans         Default destination for results 
pi            Ratio of circle circumference to
  diameter 
eps         Smallest number such that x+eps ‡ x 
flops      Floating point operations performed 
int          Infinity 
Nan or nan          Not-a-number (undefined) 
I & j        √-1 
  (square root of –1) 
nargin    Number of arguments supplied to a function 
nargout Number of arguments output by a function 
realmin The smallest usable positive real number 
realmax               The largest usable positive
  real number 
† After Version 5.0
  User's Guide, Prentice Hall, 1998 
16.7       Complex Numbers 
• Matlab implicitly
  supports complex numbers 
- no requirement for
  special functions to manipulate 
• For example 
EDU» z1=sqrt(-4)+3 
z1 = 
   3.0000+ 2.0000i 
EDU» z2=z1*(1-i) 
z2 = 
   5.0000- 1.0000i 
EDU»
  z3=5.6*sin(1.55)*i 
z3 = 
        0+ 5.5988i 
EDU» r1=imag(z3) 
 r1 = 
    5.5988 
EDU» z4=mean([z1 z2
  z3]) 
z4 = 
   2.6667+ 2.1996i 
• Note: 
-              mathematical and built-in
  function usage is exactly the same as for non-complex 
-              complex expressions yield
  complex values 
16.8       Nan & inf 
• Mathematical
  operations can often yield undefined results or those beyond the storage
  capability of the machine 
• In many languages
  these type of operation (e.g., division by zero) cause the running program to
  crash 
- not particularly
  desirable 
• Matlab has two
  special "constants" which are substituted when such operations
  occur: 
Nan        Not A Number 
inf                         Infinity 
-              this allows recovery or
  continuation 
• For example: 
EDU» undef=0/0 
Warning: Divide by
  zero. 
 | 
 
Kami ada di Jakarta Selatan. KAMI MEMBERIKAN KURSUS MATLAB ONLINE - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060.  Kami membuka kursus Matlab untuk pemula dan mahasiswa atau insinyur yang ingin memperdalam Matlab dan menerapkan dalam bidang teknikal, engineering, rekayasa, dsb. Format bimbingannya tugas-tugas yang bisa membantu Skripsi, Tesis, DISERTASI 
Bimbingan dilakukan secara online bisa lewat WA atau email Dijamin Bisa, atau bisa mengulang kembali. Kami juga dapat membantumembuatkan aplikasi atau program matlab/lainnya. Anda akan dilatih oleh Tim Profesional - HUBUNGI MASTER ENGINEERING EXPERT (MEE) 081219449060. Email: kursusmatlab@gmail.com undef = 
   NaN 
EDU» big=1/0 
Warning: Divide by
  zero. 
 | 
 
KURSUS MATLAB ONLINE Skripsi, Tesis, DISERTASI 081219449060
Selasa, 13 Januari 2015
KURSUS MATLAB ONLINE Skripsi, Tesis, DISERTASI 081219449060
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar