# Lecture2 - Lecture 2 Matlab Basics Numerical data types...

This preview shows pages 1–9. Sign up to view the full content.

Lecture 2: Matlab Basics Numerical data types, numerical precision Initializing vectors and matrices Array and matrix operations Relational operators Conditional constructs: if-elseif-else-end Loops: for-end, while-end •Strings and printing •Making 2-D plots: the plot command •Formatted output •Inline functions

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The most important command: help After typing help you will get a list of sub-topics: >> help Help topics: matlab\general - General purpose commands. matlab\ops - Operators and special characters. matlab\lang - Programming language constructs. matlab\elmat - Elementary matrices and matrix manipulation. matlab\elfun - Elementary math functions. matlab\specfun - Specialized math functions. matlab\matfun - Matrix functions - numerical linear algebra .
More specific help •After typing help you will get a list of sub-topics: >> help ops Relational operators. eq - Equal == ne - Not equal ~= lt - Less than < gt - Greater than > le - Less than or equal <= ge - Greater than or equal >=

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Even more specific help >> help eq A == B does element by element comparisons between A and B and returns a matrix of the same size with elements set to one where the relation is true and elements set to zero where it is not. A and B must have the same dimensions unless one is a scalar. A scalar can be compared with anything. What if A is a scalar and B is a matrix?? A will also be turned into a matrix! C = EQ(A,B) is called for the syntax 'A == B' when A or B is an object. >>C=(3==5) C=0 >>C=eq(4,4) C=1
Numerical Data Types •MATLAB uses only one type of number: IEEE double precision floating point complex number Double precision means 64 bits: 1 bit for the sign (+ or -), 11 bits are for the exponent , 53 bits are for the mantissa. 0 10 14159 . 3 × = π mantissa exponent Decimal floating point system 1 2 0111111 1001001000 . 1 × = Binary floating point system 5 decimal places, or 6 significant figures:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary floating point system E f x 2 × = where N N b b b f + + + = 2 .... 2 1 1 0 Note that b 0 = 1 Æ implicit bit, does not have to be stored. That why 52 bits take care of the 53 required bits of mantissa: 64 = 1 + 11 + 52 2 1 < < f is mantissa mantissa exponent sign
Machine Unit in Matlab •Smallest number in MATLAB is called eps=2 -52 eps = 2.22044604925031E-016. Check it: type >> eps in your Matlab window. What do you see? >> eps Ans = 2.2204e-016 Why don’t you see all 15 digits?? Because of the most likely default output format in your Matlab settings: format short which is the scaled fixed point format with 5 digits. You can change that to your taste!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Changing the output format Type: >> format long
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 31

Lecture2 - Lecture 2 Matlab Basics Numerical data types...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online