Presentation is loading. Please wait.

Presentation is loading. Please wait.

MatLab Program Used to Calculate Interactive

Similar presentations


Presentation on theme: "MatLab Program Used to Calculate Interactive"— Presentation transcript:

1 MatLab Program Used to Calculate Interactive
May Be Used for Programming Complex Problems Default name to store value is ans

2 MatLab Desktop : Command Window, Command History Window, Current Directory (Folder) Window

3 Terminology Main Memory – part of the computer that contains values used when running a program Identifiers – name (or label) given to a location in main memory that holds a value. Variables – location in main memory that holds a value that might change Constant – location in main memory that holds a value that will not change Statement – command for the computer in language Assignment – changing the value of a variable Expression – anything in a program that has a value Functions – a label (identifier) for code (statements) that might be run multiple times during a program

4 MATLAB Identifier Rules
Begin with one of a–z or A–Z Have remaining characters chosen from a–z, A–Z, 0–9, or _ Have a maximum length of 31 characters Should not be the name of a built-in variable, built-in function, or user-defined function Always use descriptive identifiers

5 Assignment Statements
Assignment – giving a variable a new value. The right hand side (a value) is evaluated and the value is assigned to the left hand side (a location) : x=5; y=3; z = x + y z gets the value 8 z=2*x+y now z gets the value 13 z=2*(x+y) ????

6 Expressions Expression – anything that has a value (variable, constant, literal) Operator – Symbol used to modify an expression Operand – expression modified by an operator Examples : numStudents pi numStudents + 14

7

8 Precedence Precedence - which operator is applied first in an expression having several operators. Parentheses () Exponent/Power ^ Unary plus + Unary minus - Multiplication * Division / Addition +, Subtraction -

9

10 MATLAB Functions and Constants
Matlab Functions Include : sqrt(x) log(x) log10(x) cos(x), acos(x), cosd(x), acosd(x) sin(x), asin(x), sind(x), asind(x) tan(x), atan(x), tand(x), atand(x) Arguments (or parameters) – (the “x” above inside of parenthesis) must be the correct number, data type and order

11

12 MatLab Basics Semicolon (';') to suppress output
Click on fx to Show Available Functions who to Show Variables and Values whos to Show Variables and Values help function to get description of function clc to clear Command Window clear to clear all variables

13

14

15

16

17 format Command Used to Control Format of Displayed Real Numbers
Sets Current Mode of Output Default : format short Examples : format short : 4 decimal digits format long : 16 decimal digits format short e : scientific notation (exponent) format bank : 2 decimal digits

18 Special MatLab Names ans : default location for answer
i : imaginary sqrt of -1 Inf : Infinity NaN : undefined “Not a Number” pi : π

19

20 MatLab Display disp(x) : Display the value of x
value = input('prompt') : prompt User with 'prompt'; wait for User input; place User input in value stringValue = input('prompt', 's') : prompt User with 'prompt'; wait for User input; place User input in stringValue

21 MatLab Display stringVariable = sprintf('information') : Store information in string Variable %d – decimal value %f – floating point (real) value %s – string value %5.2f – float value with minimum width of 5 and 2 decimal places Ex. moneyLine = sprintf('Your change is %5.2f',change)

22

23 Computer Limitations Computers Are Not Infinite
Computers Have Maximum Speed Computers Have Maximum Room to Store

24

25 Computer Basics Input Devices : Keyboard, Network
CPU : Central Processing Unit Memory : Main Memory, Disk Memory Output Devices : Printer, Monitor

26 Main Memory Storage Location of Data in a Computer
Used When a Program Is Running “Wiped Clean” When Computer Rebooted Bit: One Wire in Computer (generally represented by a 0 (off) or 1 (on) ) Byte: Basic Unit of Storage (Can Store One Letter of the Alphabet) (8 bits) Kilobyte (KB): 1000 (or 1024) Bytes (Pages of Text) Megabyte (MB): 1,000,000 Bytes (Large Pictures) Gigabyte (GB): 1,000,000,000 Bytes (Music Files, Video Files)


Download ppt "MatLab Program Used to Calculate Interactive"

Similar presentations


Ads by Google