Sie sind auf Seite 1von 23

EE 512 / EE 512L

Variables Output Format Character String Vector Operations Elementary Matrix Operations Utility Matrices Complex Numbers

Abbreviation of MATrix LABoratory An interactive program for numerical computation and data visualization. It is supported on Unix, Macintosh and Windows environments. Syntax are similar for DOS version MATLAB integrates mathematical computing, visualization, and a powerful language to provide a flexible environment for technical computing.

Numeric computation and algorithm development. Symbolic computation (with the built-in Symbolic Math functions). Modeling, simulation and prototyping. Data analysis and signal processing. Engineering graphics and scientific visualization.

To start MATLAB click on the MATLAB icon or type in MATLAB, followed by pressing the enter or return key at the system prompt. The screen will produce the MATLAB prompt >> (or EDU >>), which indicates that MATLAB is waiting for a command to be entered. In order to quit MATLAB, type quit or exit after the prompt, followed by pressing the enter or return key.

A Command Window which is used to enter commands and data to display plots and graphs. A Graphics Window which is used to display plots and graphs. An Edit Window which is used to create and modify M-files. M-files are files that contain a program or script of MATLAB commands. Help Window provides help information

To type a command the cursor must be placed next to the command prompt (>>). Once a command is typed and the ENTER key is pressed, the command is executed. Several commands can be type in the same line. It is not possible to go back to a previous line in the command window.

Abort In order to abort a command in MATLAB, hold down the control key and press c to generate a local abort with MATLQAAB. Semicolon(;) If a semicolon (;) is typed at the end of a command, the output of the command is not displayed. Typing % When per cent symbol (%) is typed in the beginning of a line, the line is designated as a comment. When the enter key is pressed, the line is not executed.

The clc command Typing clc command and pressing enter cleans the command window. Once the clc command is executed, a clear window is displayed. Help MATLAB has a host of built-in functions. For a complete list, refer to MATLAB users guide or refer to the on-line Help. To obtain help on a particular topic in the list, e.g., inverse, type help inv.

>> variable = expression >> A = [1 2 ; 3 4] The display will be:

A= 1 2 3 4

Order of Precedence 1st 2nd 3rd 4th parentheses exponentiation multiplication, division (equal precedence) addition and subtraction

>> 7 + 8 / 2 ans = 11

Type and press ENTER 8/2 is executed first

>> ( 7 + 8 ) / 2

Type and press ENTER 7+8 is executed first

ans = 7 .5000

>> 5 ^ 3 / 2

Type and press ENTER 5^3 is executed first , then /2 is executed next

ans = 62 .5000

Common math functions

Common exponential functions

Common number functions

A variable is a name made of a letter or a combination of several letters and digits. Variable names can be up to 63 (in MATLAB 7) characters long (31 characters on MATLAB 6.0). MATLAB is case sensitive. For instance, XX, Xx, xX and xx are the names of four different variables. It should be noted here that not to use the names of a built-in functions for a variable.
sin, cos, exp, sqrt , , etc.

>> a = 12 a= 12

Assign 12 to a

>> b = 4

Assign 4 to b

b= 4

>> c = ( a b ) + 40 a / b * 10

Assign the value of the expression on the right-hand side to the variable c
c= 18

In a right triangle shown a=11cm and c=21cm. Define a and c as variables, then: a) Using Pythagorean theorem, calculate b by typing one line in the command window. b) Using b from part a), and the acos(x) function, calculate the angle in degrees, in degrees, typing in one line in the command window

>> a = 11 ; >> c = 21 ; >> b = sqrt (( c ^ 2 ) ( a ^ 2 ) ) b = 17 . 8885

c a b

) >> = a cos ( a c
= 1 . 0195

In the triangle shown a=18cm, b=35cm and c=50cm. Define a,b and c as variables, and then calculate the angle, ,(in degrees) by substituting the variables in the law of cosines. 2 2 2

>> a = 18 ; >> b = 35 ; >> c = 50 ;

c = a + b 2 ab cos
c

>> beta=a cos ((c ^ 2 -b^ 2 -a^ 2 )/(- 2*a*b)) beta = 2 .4261
>> beta= (a cos ((c^ 2 -b^ 2 -a^ 2 )/(- 2*a*b)) ) * (180 / pi ) beta = 139 . 0046

Das könnte Ihnen auch gefallen