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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 .
Background image of page 2
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 >=
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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:
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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!
Background image of page 7

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

View Full DocumentRight Arrow Icon
Changing the output format Type: >> format long
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online