UPLOAD

    2.8K

    INTRODUCTION TO MATLAB

    Published: September 05, 2019

    Matlab

    Comments

    INTRODUCTION TO MATLAB

    • 1. Slide1 INTRODUCTION TO MATLAB
    • 2. Slide2 INTRODUCTION TO MATLAB
    • 3. Slide3 Matlab image consists of 4 main sections in the classic view: 1. Command Screen 2. Working Area 3. Used Folder 4. Command History
    • 4. Slide4 Command Screen This is the screen where we enter the commands. Used Folder This is the folder where we saved our work. Matlab looks at this folder to find them.
    • 5. Slide5 Working Area When working with Matlab, constants and variables defined during operation are defined here. When we call constants, and variables held in the workspace in Matlab, they are known throughout that session. They are deleted when we close the program, Matlab. They are not remembered in the next session.
    • 6. Slide6 Command History It is a screen that makes it easy to write programs in Matlab. The commands we entered before appearing on this screen. When we want to enter the same command again, we can enter here.
    • 7. Slide7 Arithmetic Operations in Matlab Matlab is also a powerful calculator. When you enter arithmetic operations such as addition, subtraction, division, multiplication, and above from Matlab's command screen and press enter key, it will give us the results as 'ans' (answer). Examples >> 2+3ans =5 >> 2-2ans =0 >> 2/3ans =0.6667 >> 5^3ans =125 >> 5^-3ans =0.0080
    • 8. Slide8 Vector Definition in Matlab In Matlab, we can define vector by typing the following commands in Matlab subject window. line_vector =[1 2 3] or [1,2,3] column_vector =[1;2;3] The vectors we have identified will be seen as names in Matlab's field of study.
    • 9. Slide9 Transpose of a Vector in Matlab In Matlab, the process of receiving a transposition of a vector is the displacement of rows and columns. That is, a vector x defined as a row vector is converted to a column vector with the expression x '. xt=x’
    • 10. Slide10 Example x = [135]; x_trans = x’ When we type these commands and press enter, the result is: x_trans = 1 3 5
    • 11. Slide11 Another way to define a vector in Matlab is given below. If there is a rule between the elements that make up the vector (it continues to increase with a certain amount of increment), then we can define a vector as follows. odd_numbers = 1:2:11 1 = initial value 11 = end value 2 = step size
    • 12. Slide12 Example (Vector Identification) On the command line: odd_numbers = 1:2:11 If we type and press enter, we get the following answer. odd_numbers = 1 3 5 7 9 11 The step size can be selected in negative and non-integer values.
    • 13. Slide13 Example (Vector Identification) x = 3.5:-0.5:1 type and press enter: x = 3.5000 3.0000 2.5000 2.0000 1.5000 1.0000
    • 14. Slide14 Using Linspace in Matlab Another way to create a Matlab 'vector is to use the linspace command. As we will remember odd_numbers = 1:2:11 We could create a vector by specifying the start value, increment amount, and end values. Similarly, using the linspace command; we can also create a vector by specifying the start - end value and the number of elements. linspace: Creates an evenly spaced array with n elements with an initial value of x1 and an end value of x2.
    • 15. Slide15 Example (Linspace Application) Now let's recreate the odd_numbers vector we created in the previous example using the linspace command. odd_numbers = linspace(1,11,6) If we type and press enter; odd_numbers 1.3 5 7 9 11 We get the result. As you can see here, when using the linspace command, the number of elements of the desired vector is entered, NOT STEP SIZE. Matlab will set the start and end values to be equal to the number of elements.
    • 16. Slide16 Linspace Example numbers = linspace(1,15,7) is entered and the enter key is pressed. numbers = 1.0000 3.3333 5.6667 8.0000 10.3333 12.666 15.0000 we get the answer
    • 17. Slide17 Using Logspace in Matlab The Longspace command helps us construct logarithmic vectors. Longspace structure is as follows. longspace(a,b,n) Logspace: Creates an array with n elements with an initial value of 10a, an end value of 10b, and a multiple of equal elements.
    • 18. Slide18 Example (Logspace Application) From the command window x = logspace(1,5,3) If you enter the command; x = 10.1000 100000 we get a vector in the form of.
    • 19. Slide19 Sum Command in Matlab sum (x) = Collects all elements of the vector with each other. Example x = [-8 0 -1 3 4 5] total = sum(x) total = -1.5000
    • 20. Slide20 Mean Command in Matlab mean (x) = Returns the average of the elements of the vector. Example x = [-8 0 -1 3 4 5] mean = -0.3000