(Parte 8 de 16)

>> A = 5;

You can type several commands on the same line by separating them with comnlas or semicolons. If you separatethem with commas, they will be displayed, and if you usethe semicolon, they will not. For example,

>> a - 4,A = 6;x = .1 ;

MATLAB treats names in a case-sensitive rnanner-that is. the nan)e a is not the same as the name a. To illustrate this. enter

>> a and then enter

>>A See how their values are distinct. Thev are distinct names.

twe short Iong short e long e long g long eng bank frT-Tbl zf Ttr ='1.t- st .-f J _A x I

"L4

-z th j€- 15/ zl-+Z] X+?

2.2 ASSIGNMENT23

We can assign complex values to variables. since MATLAB handles complex arith- metic automatically. The unit irnaginary number "/J ir preassigned to the variable i.

Consequently, a complex value can be assigned simply as in

>> x = 2+i*4

2.0 + 4.0i

It should be noted that MATLAB allows the symbol j inary number for input. However, it always uses an i

>> x = 2+1*4

2.0 + 4.0i

There are several predefined variables. fbr example. pi. >- pi

3 . r4r6

Notice how MATLAB displays fbur decinral places. If you desire additional precision, enter the fbllowing:

>> format long

Now when pi is enteled the result is displayed to l5 signilicant figures: >> pi

1.141592b5-1 58979

To return to the four decimal version, type >> format short

The f<rllowing is a summary of the format commands you will employ routinely in engincering and.scientific calculations. They all have the syntax: f ormat typr...

to be used to represent the unit imagfor display. For example,

Exompletwe Result

-cho] t Lcrng srrort e lonlJ e shorl: g lonq g short eng long eng bank

Sco ed fixed point formct with 5 digits Sccried frxed-point formoi with 15 diglh for double ond Z digits for single Flooiing'point formct wiih 5 diqits

Flooiing point lormot wifh l5 digiis for double ond / dlgits lor single Besl of fixed or floofing-poinl lormot with 5 dictlts

Best o[ [ixed or flooting poinl formof with 15 dlgits for double andTaglsforsingie

Engineerlng formof with ol lecsl 5 digits ond o power ihot is cr rnutlple of 3 Engineer ng formot wiih excclly 16 significont digits ond o power thot s o mu tiple of 3 Fixed dollors ond cents

3 . r416 i.1415q1b5J58979 l.1415e+0tr0 3. 14 l 592653589793e+0 3.r416 3 .1 41592.65],5897 9

1.1416er000 3 . 1 41592 6535897 9e+0

ffiE\z\ a +i-_- --:-----;:a, . IF{'J

-a. [h--T

!1,€ - el 5ta-* 4'"1

Iel +Z} X+

24 MATLAB FUNDAMENTALS

2.2.2 Arroys, Vectors qnd Mqtrices

An arrat' is a collection of values that are represented by a single variable name. One- dincnsirnalarral't arc callcd tu'/ort and two-dinensional anavs are c'alled nrutnce:. The scalars used in Section 2.2.1 are actually a matrix with one low and one column.

Brackets are used to enter arrays in the comnranil mode. For exan.rple, a row vector can be assisned as fbiiows:

Note that this assignment overrides the previous assignment of a : 4.

In practice, row vectors are rarely used to solve rnathematical problerns. When we speak of vectors. we usually ret-er to column vectors, which are more contmonly used. A column vector can be entered in several ways. Try them.

I0 l or. by transposing a row vector with the ' operator,

>> Lr = | 2, 4 6 I 10 I' Tlre result in all three cases will be

A rnatrix of values can be assigned as lblkrws:

In addition. the Enter key (carriage return) can be used to separirte the rows. For example.

in the following case, the Enter key woulcl be struck after the 3. the 6 and the I to assign the matrix:

.->A.. lr23 456

:5ystzf LIZ _r -{

(Parte 8 de 16)

Comentários