Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com. >> x = 5 x = 5 Your variables are: x >> x = y = x + 5 y = 10 >> y = x*5 y = 25 >> y = x^2 y = >> x x = 25 5 >> y = x^3
y = 125 >> y = 3 + 55-62 + 4-5 y = -5 >> y = 3*2+3*2 y = 12 >> y = 3* 2+3 * 2 y = 12 >> y = 3* (2+3) * 2 y = 30 >> y = 5 y = 5 >> x = 3 x = 3 >> x/y 0.6000 >> y/x 1.6667 >> x\y Commented [LS1]: X divides into y. Seldom used. Not as intuitive.
>> y\x 1.6667 0.6000 >> help elfun Elementary math functions. Trigonometric. sin - Sine. sind - Sine of argument in degrees. sinh - Hyperbolic sine. asin - Inverse sine. asind - Inverse sine, result in degrees. asinh - Inverse hyperbolic sine. cos - Cosine. cosd - Cosine of argument in degrees. cosh - Hyperbolic cosine. acos - Inverse cosine. acosd - Inverse cosine, result in degrees. acosh - Inverse hyperbolic cosine. tan - Tangent. tand - Tangent of argument in degrees. tanh - Hyperbolic tangent. atan - Inverse tangent. atand - Inverse tangent, result in degrees. atan2 - Four quadrant inverse tangent. atan2d - Four quadrant inverse tangent, result in degrees. atanh - Inverse hyperbolic tangent. sec - Secant. secd - Secant of argument in degrees. sech - Hyperbolic secant. asec - Inverse secant. asecd - Inverse secant, result in degrees. asech - Inverse hyperbolic secant. csc - Cosecant. cscd - Cosecant of argument in degrees. csch - Hyperbolic cosecant. acsc - Inverse cosecant. acscd - Inverse cosecant, result in degrees. acsch - Inverse hyperbolic cosecant. cot - Cotangent. cotd - Cotangent of argument in degrees. coth - Hyperbolic cotangent. acot - Inverse cotangent. acotd - Inverse cotangent, result in degrees. acoth - Inverse hyperbolic cotangent. hypot - Square root of sum of squares.
Exponential. exp - Exponential. expm1 - Compute exp(x)-1 accurately. log - Natural logarithm. log1p - Compute log(1+x) accurately. log10 - Common (base 10) logarithm. log2 - Base 2 logarithm and dissect floating point number. pow2 - Base 2 power and scale floating point number. realpow - Power that will error out on complex result. reallog - Natural logarithm of real number. realsqrt - Square root of number greater than or equal to zero. sqrt - Square root. nthroot - Real n-th root of real numbers. nextpow2 - Next higher power of 2. Complex. abs angle complex conj imag real unwrap isreal cplxpair - Absolute value. - Phase angle. - Construct complex data from real and imaginary parts. - Complex conjugate. - Complex imaginary part. - Complex real part. - Unwrap phase angle. - True for real array. - Sort numbers into complex conjugate pairs. Rounding and remainder. fix - Round towards zero. floor - Round towards minus infinity. ceil - Round towards plus infinity. round - Round towards nearest integer. mod - Modulus (signed remainder after division). rem - Remainder after division. sign - Signum. >> floor(1.2939580) 1 >> ceil(1.2932930910) 2 >> round(1.3) 1
>> round(1.6) 2 >> round(1.5) 2 >> rem(3,5) 3 >> abs(-1) 1 >> abs(1) 1 >> pi 3.1416 >> 0/1 0 >> 1/0 Inf >> 0/0 NaN
ans 1x1 8 double y 1x1 8 double >> z = 3.1416 Commented [LS2]: This is type double. z = 3.1416 >> z1_int = int16(z) z_int = Commented [LS3]: With this, I type-cast the double into an integer of 16 bits and store it in z1_int, another variable. 3 ans 1x1 8 double y 1x1 8 double >> z_int8 = int8(10.1209) Commented [LS4]: z is still a double. Commented [LS5]: z_int is an integer of 16 bits. What is the largest number that int16 can represent? z_int8 = 10 ans 1x1 8 double y 1x1 8 double z_int8 1x1 1 int8 >> z_int8 = 1029020 z_int8 = 1029020
ans 1x1 8 double y 1x1 8 double z_int8 1x1 8 double >> intmin('int8') Commented [LS6]: Convenience (AND POTENTIAL PIT FALL!!) MATLAB automatically change the type of the variable z_int8 from an integer of 8 bits to a double of 8 bytes!! -128 >> intmax('int8') 127 >> intmin('uint8') 0 >> intmax('uint8') 255 >> y = 'a' y = a ans 1x1 1 uint8 y 1x1 2 char z_int8 1x1 8 double >> z_string = 'abcde' z_string = abcde
ans 1x1 1 uint8 y 1x1 2 char z_int8 1x1 8 double z_string 1x5 10 char Commented [LS7]: A vector of 5 characters. Length = 5. >> z_string = 'ab cde' z_string = ab cde ans 1x1 1 uint8 y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> red_flag = 'true' red_flag = Commented [LS8]: This is assigning a string (i.e., a vector of characters) to the variable red_flag. true ans 1x1 1 uint8 red_flag 1x4 8 char y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> red_flag = true red_flag = 1 Commented [LS9]: As a result, this is still a vector of characters. Commented [LS10]: This makes red_flag a logical variable. Commented [LS11]: This is a keyword. And it is represented internally in Matlab as 1.
ans 1x1 1 uint8 red_flag 1x1 1 logical y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> red_flag = false red_flag = Commented [LS12]: See, now this is a logical variable. Commented [LS13]: Another keyword. Represented internally as 0. 0 >> num = int32('a') num = Commented [LS14]: American Standard Code for Information Exchange Every letter on our keyboard is represented by a number. 97 >> num = int32('b ) num = 98 >> num = int32( c') num = 99 >> num = int32('a ) num = 65 >> num = int32( B ) num = 66 >> num = int32('c ) num = 67 >> num = int32(? ) num =
63 >> num = int32('$ ) num = 36 >> num = int32('# ) num = 35 >> num = int32(' ) num = 32 >> char('abcd' + 1) Commented [LS15]: Cool!!! I can shift the characters by 1! bcde >> v = [1 2 3 4 5] v = 1 2 3 4 5 ans 1x4 8 char num 1x1 4 int32 red_flag 1x1 1 logical v 1x5 40 double y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> v c = [1; 2; 3 ; ; 4; 5] c = 1 2 3 4
5 >> matrix 2 = [1 2; 3 4] m2 = 1 2 3 4 >> m3 = [1 2 3; 10 10 10] m3 = 1 2 3 10 10 10 >> m3 = [1 2 3; 10 10 10]]1]0]; 10 10 10 10]4; 10 10 10 10]; 10 10 10 10;]]7]]8]]9]]1]0]]] m3 = [1 2 3 4; 10 10 10 10; 7 8 9 10]] {Error: Unbalanced or unexpected parenthesis or bracket. } >> m3 = [1 2 3 4; 10 10 10 10; 7 8 9 10]]] m3 = 1 2 3 4 10 10 10 10 7 8 9 10 >> vec = [1: 5 1:5 vec = 1 2 3 4 5 >> vec = 1:2:11 vec = 1 3 5 7 9 11 >> vec 1 = 1:2:9 1 3 5 7 9 >> v2 = 11:17 v2 = 11 12 13 14 15 16 17
>> newvector = [v1 v2] newvector = 1 3 5 7 9 11 12 13 14 15 16 17 ans 1x4 8 char c 5x1 40 double m2 2x2 32 double m3 3x4 96 double newvector 1x12 96 double num 1x1 4 int32 red_flag 1x1 1 logical v 1x5 40 double v1 1x5 40 double v2 1x7 56 double vec 1x6 48 double y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> newvector(1) 1 >> newvector(1)1) 2) 3 >> newvector newvector = 1 3 5 7 9 11 12 13 14 15 16 17 >> newvecotr tor[2] newvector[2] {Error: Unbalanced or unexpected parenthesis or bracket. } >> newcge vector(2)
3 >> newvector(6) 11 >> newvector(4:5 6( ) 7 9 11 >> newvectro([11 or([1 1 6 11]) >> ans' 1 11 16 1 11 16 >> newvector newvector = 1 3 5 7 9 11 12 13 14 15 16 17 >> newvector(5) 1) = 10 newvector = 10 3 5 7 9 11 12 13 14 15 16 17 >> newvector(13) = 11 1000 newvector = Columns 1 through 9 10 3 5 7 9 11 12 13 14 Columns 10 through 13 15 16 17 1000 >> newvector(13) = 1000) = 1000 5) = 1000
newvector = Columns 1 through 9 10 3 5 7 9 11 12 13 14 Columns 10 through 15 15 16 17 1000 0 1000 >> vecto 1 = [2 5 18 10] >> v1' 2 5 18 10 2 5 18 10 >> v1 v1' ' 2 5 18 10 >> v1' 2 5 18 10 >> v1' 2 5 18 10 >> v1'
2 5 18 10 >> v1' 2 5 18 10 >> v1' 2 5 18 10 >> mat = [2 4 3 1; 2 5 6] mat = >> mat(1) 4 3 1 2 5 6 4 >> mat(6) 6 >> mat(2) 2 >> mat(2)) 3) 3 >> mat(3) 4) 5
>> mat(4) 5) 1 >> mat mat = 4 3 1 2 5 6 >> rand2 (2) 0.8147 0.1270 0.9058 0.9134 >> rand(3) 0.6324 0.5469 0.1576 0.0975 0.9575 0.9706 0.2785 0.9649 0.9572 >> rand(1,30 ) 0.4854 0.8003 0.1419 >> zeros(3) 0 0 0 0 0 0 0 0 0 >> ones(3) 1 1 1 1 1 1 1 1 1 >> twos(3) {Undefined function 'twos' for input arguments of type 'double'. }
>> int mat = [100 77; 28 14] mat = 100 77 28 14 >> in mat(1) = 100 mat = 100 77 28 14 >> mat(1) = 1000 28 mat = 28 77 28 14 >> mat(1) = 28 ) = 2) = ) = 6 0 mat = >> mat mat = 28 77 60 14 28 77 60 14 >> mat(2,:) = [600 140] mat = 28 77 600 140 >> mat(:,2) = [777787 140000] mat = >> v1 28 7777 600 140000 2 5 18 10
>> lengtyh h(v1) 4 >> le length(mat) 2 >> size9 (mat) 2 2 >> matrix mymatr = [1 2 3; 9 10 11] mymat = 1 2 3 9 10 11 >> si z size(myamat mat) 2 3 >> reshape rto ot(mymat) {Undefined function 'rot' for input arguments of type 'double'. } >> rot90(mymat) 3 11 2 10 1 9 >> rot90 fliplr(k mymat) 3 2 1 11 10 9 >> flipud(mymat)
>> v = [] v = 9 10 11 1 2 3 [] >> m vec 1 2 5 18 10 >> [] [] ans 2x3 48 double c 5x1 40 double m2 2x2 32 double m3 3x4 96 double mat 2x2 32 double mymat 2x3 48 double newvector 1x15 120 double num 1x1 4 int32 red_flag 1x1 1 logical v 0x0 0 double v1 0x0 0 double v2 1x7 56 double vec 1x6 48 double y 1x1 2 char z_int8 1x1 8 double z_string 1x6 12 char >> vec = 1:5 vec = 1 2 3 4 5 >> vec(3) = [] vec =
1 2 4 5 >> exit [?1l>[1mcse[0m fac/lksoh> exit exit Script done on Thu 25 Aug 2016 03:16:37 PM CDT