Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPS 1371 Introduction to Computing for Engineers MatLab.

Similar presentations


Presentation on theme: "CMPS 1371 Introduction to Computing for Engineers MatLab."— Presentation transcript:

1 CMPS 1371 Introduction to Computing for Engineers MatLab

2 Getting Started In Windows click on the following: Programs Math & Science  MatLab R2008a

3 Getting Started MATLAB opens to a default window configuration

4 MATLAB uses a standard windows menu bar To exit MATLAB use the close icon

5 Command Window Enter commands at the prompt Current Directory MATLAB Windows Command History Workspace Window

6 MATLAB Windows MATLAB uses several different windows to display data, commands and results. They are not necessarily all open at once

7 Command Window Similar to a scratch pad Once you hit enter, you can’t edit any commands You can retype them or use the arrow keys to retrieve commands and edit them before hitting enter again Command Window

8 Command History Records the commands you issue in the command window When you exit the command window, or when you issue the clc command, the command window is cleared But the command history remains Command History

9 You can transfer commands from the command history to the command window Double click on a command Click and drag

10 Workspace Window Keeps track of the variables you’ve defined Name Value Class Size Bytes You may need to click on the name bar and select size and bytes in order to see these parameters Workspace Window

11 When you define variables in the command window, they are listed in the workspace window

12 Current Directory The current directory window is a list of files When you try to load information from a file or try to save information – MATLAB uses the current directory

13 Document Window If you double click on any variable in the workspace window MATLAB launches a document window containing the array editor You can edit variables in the array editor

14 Document Window

15 Figure Window When Figures are created a new window opens It’s extremely easy to create graphs in MATLAB

16 The semicolon suppresses the output from each command

17

18 Editing Window This window allows you to type and save a series of commands without executing them There are several ways to open an editing window From the file menu With the new file icon

19 Open an editing window from the file menu or with the new file icon

20 Save and Run Write your code in the editing window, then run it using the Save and Run icon

21 Solving Problems We’ve already solved some simple problems We need to understand how MATLAB works to solve more complicated problems

22 Variables MATLAB allows you to assign a value to a variable A=3 Should be read as A is assigned a value of 3 Use the variables in subsequent calculations

23 Naming Variables All names must start with a letter They may contain letters, numbers and the underscore ( _ ) Names are case sensitive There are certain keywords you can’t use

24 Keywords Use the iskeyword function for a list of keywords >>iskeyword ans = 'break' 'case' 'catch' 'continue' 'else' 'elseif' 'end' 'for' 'function' 'global' 'if' 'otherwise' 'persistent' 'return' 'switch' 'try' 'while'

25 Which of these names are allowed in MATLAB? test Test if my-book my_book Thisisoneverylongnamebutisitstillallowed? 1stgroup group_one zzaAbc z34wAwy?12# sin log x x x x x x bad idea

26 Scalar Calculations You can use MATLAB like you’d use a calculator >> 9 + 10 ans=19 Command Prompt Result

27 Assignment Operator To define a variable a we might type a=1+2 which should be read as: “a” is assigned a value of 1+2

28 Order of Operation Same as you’ve learned in math class Same as your calculator Parentheses first Exponentiation Multiplication / division Addition / subtraction

29 Order of Operation 5*(3+6)= 45 5*3+6= 21 White space does not matter!!! 5*3 + 6= 21

30 Parentheses Use only ( ) { } and [ ] mean something different MATLAB does not assume operators 5 * (3+4) not 5(3+4)

31 Compute from left to right 5*6/6*5= 25 5*6/(6*5)= 1

32 Here’s an example Find the surface area of a cylinder r = radius r = 5 h = height h = 10 π r 2 2π r * h

33

34 Try some Type each expression on the command line and then press Enter >> 7 + 8 / 2 >> (7 + 8) / 2 >> 5 ^ 3 / 2 >> sqrt(64) >> x = 15 >> x = 3 * x – 12 >> y = pi >> z = y * 2 >> A = 12; >> B = 4; >> C = A / B + A – B * 2; >> C


Download ppt "CMPS 1371 Introduction to Computing for Engineers MatLab."

Similar presentations


Ads by Google