Download presentation
Presentation is loading. Please wait.
Published byJasper Murphy Modified over 9 years ago
2
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP Screen Elementary Math Functions Rounding Functions Discrete Mathematics Trigonometric Function Data Analysis Function Maximum and Minimum Mean and Median
3
Sums and Products
5
Sorting Values
6
Matrix Size
7
Variance and Standard Deviation
8
Normal Distribution
10
Random Numbers Random numbers are often used in engineering calculations to simulate measured data Measured data rarely behave exactly as predicted by mathematical models, so we can add small values of random numbers to our predictions to make a model behave more like a real system Random numbers are also used to model games of chance Two different types of random numbers can be generated in MATLAB: Uniform random numbers Gaussian random numbers
12
Uniform Random Numbers Uniform random numbers are generated with the rand function. These numbers are evenly distributed between 0 and 1 We can create a set of random numbers over other ranges by modifying the numbers created by the rand function For example: to create a set of 100 evenly distributed numbers between 0 and 5 first create a set over the default range with the command r = rand(100,1); This results in a 100x1 matrix of values Now we just need to multiply by 5 to expand the range to 0 to 5: r = r * 5;
13
Example Continued…. If we want to change the range to 5 to 10, we can add 5 to every value in the array: r = r + 5; The result will be random numbers varying from 5 to 10. We can generalize these results with the equation x=(max - min). random_number_set + min
14
Gaussian Random Numbers
15
Continued…. If we need a data set with a different average or a different standard deviation, we start with the default set of random numbers and then modify it Since the default standard deviation is 1, we must multiply by the required standard deviation for the new data set Since the default mean is 0, we’ll need to add the new mean: x = standard_deviation. random_data_set + mean For example: to create a sequence of 500 Gaussian random variables with a standard deviation of 2.5 and a mean of 3, type x = randn(1500)*2.5 + 3;
16
Complex Numbers MATLAB includes several functions used primarily with complex numbers Complex numbers consist of two parts a real component an imaginary component For example: 5+3iis a complex number. The real component is 5, and the imaginary component is 3. Complex numbers can be entered into MATLAB in two ways: as an addition problem, such as A = 5 + 3i or A = 5+3*i or with the complex function, as in A = complex(5,3) which returns A = 5.0000 + 3.0000i
17
Continued…. As is standard in MATLAB, the input to the complex function can be either two scalars or two arrays of values Thus, if x and y are defined as x = 1:3; y = [-1,5,12]; then the complex function can be used to define an array of complex numbers as follows: complex(x,y) ans = 1.0000 - 1.0000i 2.0000 + 5.0000i 3.0000 +12.0000i
18
real and imag Function The real and imag functions can be used to separate the real and imaginary components of complex numbers For example: for A = 5 + 3*i, we have real(A) ans =5 imag(A) ans =3
19
isreal Function The isreal function can be used to determine whether a variable is storing a complex number It returns a 1 if the variable is real and a 0 if it is complex Since A is a complex number, we get isreal(A) ans =0 Thus, the isreal function is false and returns a value of 0
20
Conjugate of Complex Number The complex conjugate of a complex number consists of the same real component, but an imaginary component of the opposite sign The conj function returns the complex conjugate: conj(A) ans = 5.0000 - 3.0000i The transpose operator also returns the complex conjugate of an array, in addition to converting rows to columns and columns to rows Thus, we have A' ans = 5.0000 - 3.0000i
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.