• No se han encontrado resultados

SINTAXIS Y MANIPULACION DE MATRICES SESIONES EN CLASE

N/A
N/A
Protected

Academic year: 2020

Share "SINTAXIS Y MANIPULACION DE MATRICES SESIONES EN CLASE"

Copied!
26
0
0

Texto completo

(1)

SINTAXIS Y MANIPULACION DE MATRICES

PRIMERA SESION.

>> %SINTAX PARA INGRESAR MATRICES

>> A=[16 3 2 13;5 10 11 8;9 6 7 12;4 15 14 1]

A =

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

>> %SUMA DE LAS COLUMNAS DE "A"

>> SCA=sum(A)

SCA =

34 34 34 34

>> %SUMAR RENGLONES DE "A"

>> %NOTA: pasa sumar los renglones de "A" se transpone la matriz "A" y se suman las columnas de "A'"

>> SRA=sum(A')'

SRA =

34

34

(2)

34

>> trA=A'

trA =

16 5 9 4

3 10 6 15

2 11 7 14

13 8 12 1

>> %SUMAR LOS TERMINOS DE LA DIAGNOMAL PRINCIPAL

>> DDA

Undefined function or variable 'DDA'.

>> SDA=sum(diag(A))

SDA =

34

>> diag(A)

ans =

16

10

7

(3)

>> %EXTRAER LA ANTIDIAGONAL DE "A"

>> %girar de izquierda a derecha la matriz "A" von fliplr

>> Ag=fliplr(A)

Ag =

13 2 3 16

8 11 10 5

12 7 6 9

1 14 15 4

>> %SUMAR LOS TERMINOS DE LA ANTIDIAGONAL DE "A"

>> %es equivalente a sumar los terminos de la diagonal principal "Ag"

>> SAA=sum(diag(Ag))

SAA =

34

>> SAA2=sum(diag(fliplr(A)))

SAA2 =

(4)

>> A

A =

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

>> %EXTRACCION DE UN ELEMENTO PARTICULAR DE UNA MATRIZ

>> %Extraer 3er renglon 4ta columna (12)

>> A(3,4)

ans =

12

>> %Extraer elemento del 3er renglon 2da columna

>> A(3,2)

ans =

6

>> %EXTRAER UNA PORCION DE LA MATRIZ

>> %Extraer los elementos 10,11 y 8

(5)

ans =

10 11 8

>> A(2,2,3,4)

Index exceeds matrix dimensions.

>> %Extraer todos los elementSo del cuarto renglón

>> A(4,1:4)

ans =

4 15 14 1

>> A(4,:)

ans =

4 15 14 1

>> %Extraer todos los elementos de la 2da columna

>> A(:,2)

ans =

3

10

6

(6)

SEGUNDA SESION

>> A

A =

16 3 2 3

5 10 11 8

9 6 7 12

4 15 14 1

>> % de la tercera columna de A extraer los elementos que van del segundo al 4 renglón

>> A(2:4,3)

ans =

11

7

14

>> A(:,4)

ans =

3

8

12

1

(7)

ans =

4 15 14 1

>> %extraer la segunda columna de A

>> A(:,2)

ans =

3

10

6

15

>> A(2,2:4)

ans =

10 11 8

>> %extraer la submatriz

>> A(2:4,2:4)

ans =

10 11 8

6 7 12

(8)

>> A(2:4,1:2)

ans =

5 10

9 6

4 15

>> A(1:4,1:2)

ans =

16 3

5 10

9 6

4 15

>> A(1:2,1:2)

ans =

16 3

5 10

>> A

(9)

16 3 2 3

5 10 11 8

9 6 7 12

4 15 14 1

>> A(1:2,2:4)

ans =

3 2 3

10 11 8

>> A(1:4,1:2)

ans =

16 3

5 10

9 6

4 15

>> %intercambio de renglones en una matriz

>> %intercambiar los renglones 2 y 4 de la matriz A

>> A([1 4 3 2],:)

ans =

16 3 2 3

(10)

9 6 7 12

5 10 11 8

>> A(:,[1 2 4 3])

ans =

16 3 3 2

5 10 8 11

9 6 12 7

4 15 1 14

>> A(:,[3 2 1 4])

ans =

2 3 16 3

11 10 5 8

7 6 9 12

14 15 4 1

>> % primero y cuarto renglon y primera y cuarta columna

>> A([4 2 3 1],[4 2 3 1])

ans =

1 15 14 4

8 10 11 5

(11)

3 3 2 16

>> %extraccion de los elementos de una matriz que cumplen cierta condición

>> A(A>S)

Undefined function or variable 'S'.

>> A(A>s)

Undefined function or variable 's'.

>> A(A>5)

ans =

16

9

10

6

15

11

7

14

8

12

>> %extraccion de los elementos de A que son menores que 5

>> A(A<5)

(12)

4

3

2

3

1

>> A(5>A<10)

ans =

16

5

9

4

3

10

6

15

2

11

7

14

3

8

12

1

(13)

ans =

Empty matrix: 0-by-1

>> A(5<A<10)

ans =

16

5

9

4

3

10

6

15

2

11

7

14

3

8

12

1

>> A(A>5 & A<10)

(14)

9

6

7

8

TERCERA SESION

>> % Generar matriz aleatoria

>> M=rand(3)

M =

0.8147 0.9134 0.2785

0.9058 0.6324 0.5469

0.1270 0.0975 0.9575

>> size(M)

ans =

3 3

>> N=rand(3,4)

N =

0.9649 0.9572 0.1419 0.7922

0.1576 0.4854 0.4218 0.9595

0.9706 0.8003 0.9157 0.6557

(15)

P =

4.0714 5.5155 4.3424 4.0923

5.6983 5.4863 5.4121 4.1943

5.8680 4.7845 4.0637 5.6469

5.3575 5.3110 4.5538 5.3897

>> % Extraer de la matriz P la segunda columna y asignarla a la variable P2

>> P2=P[2,:]

P2=P[2,:]

|

Error: Unbalanced or unexpected parenthesis or bracket.

>> P2=P(:,2)

P2 =

5.5155

5.4863

4.7845

5.3110

>> % extraer el segundo renglon de la matriz P y asignarla a PR3

>> PR3=P(2,:)

PR3 =

(16)

>> %sumar las columnas de M y asignarla a la variable SCM

>> SCM=sum(M(:,:))

SCM =

1.8475 1.6433 1.7829

>> SCM=sum(M)

SCM =

1.8475 1.6433 1.7829

>> %sumar los elemntos del tercer renglon de M

>> % y asignarlo S3RM

>> S3RM=sum(M(3,:))

S3RM =

1.1820

>> %intercambiar la primera y cuarta columna de p

>> P14=P[4 2 3 1]

P14=P[4 2 3 1]

|

Error: Unbalanced or unexpected parenthesis or bracket.

(17)

P14=P[:,4 2 3 1]

|

Error: Unbalanced or unexpected parenthesis or bracket.

>> P14=P([:,4 2 3 1])

P14=P([:,4 2 3 1])

|

Error: Unexpected MATLAB operator.

>> P14=P(:,[4 2 3 1])

P14 =

4.0923 5.5155 4.3424 4.0714

4.1943 5.4863 5.4121 5.6983

5.6469 4.7845 4.0637 5.8680

5.3897 5.3110 4.5538 5.3575

>> p

Undefined function or variable 'p'.

Did you mean:

>> P

P =

4.0714 5.5155 4.3424 4.0923

5.6983 5.4863 5.4121 4.1943

(18)

5.3575 5.3110 4.5538 5.3897

>> %intercambiar el segundo y cuarto renglon

>> P24=P([1 4 3 2],:)

P24 =

4.0714 5.5155 4.3424 4.0923

5.3575 5.3110 4.5538 5.3897

5.8680 4.7845 4.0637 5.6469

5.6983 5.4863 5.4121 4.1943

>> Q=[1 2 ;3 4]

Q =

1 2

3 4

>> %multiplicar Q por el escalar 5

>> Qx5=5*Q

Qx5 =

5 10

15 20

>> %sumar a Q el escalar 3

(19)

Q+3=3+Q

|

Error: The expression to the left of the equals sign is not a valid target for an assignment.

>> 3+Q

ans =

4 5

6 7

>> % dividir Q para el escalar 2

>> Q/2

ans =

0.5000 1.0000

1.5000 2.0000

>> rat(ans)

ans =

1 + 1/(-2)

2 + 1/(-2)

1

2

(20)

Undefined function 'pretty' for input arguments of type 'char'.

>> % dividir los elementos de la primera columna de Q entre los correspondientes de la segunda columna

>> Q2=Q(2,:)Q/(:,2)

Q2=Q(2,:)Q/(:,2)

|

Error: Unexpected MATLAB expression.

>> % los operadores de arreglos permiten realizar operaciones termino a termino

>> Q2=Q(2,:)./Q(:,2)

Error using ./

Matrix dimensions must agree.

>> Q2=Q(:,1)./Q(:,2)

Q2 =

0.5000

0.7500

>> Q*Q

ans =

7 10

15 22

(21)

Q.^

|

Error: Expression or statement is incomplete or incorrect.

>> Q^2

ans =

7 10

15 22

>> Q.^2

ans =

1 4

9 16

>> Q.*Q

ans =

1 4

9 16

>> plot(P(:,4) P(:,1))

plot(P(:,4) P(:,1))

|

(22)

>> plot(P(:,4),P(:,1))

>> plot(P(:,1),P(:,4))

>>

CUARTA SESION

>> % CONCATENAR LA MATRIZ T CON LA MATRIZ VG

>> DATOS=[T VG]

DATOS =

34.1000 29.0000 5.1000 660.0000

30.0000 27.0000 6.0000 700.0000

32.0000 28.0000 5.3000 550.0000

29.0000 28.0000 5.4000 750.0000

33.0000 27.0000 7.0000 800.0000

31.0000 26.0000 6.3000 850.0000

(23)

DATOS2 =

34.1000 29.0000

30.0000 27.0000

32.0000 28.0000

29.0000 28.0000

33.0000 27.0000

31.0000 26.0000

5.1000 660.0000

6.0000 700.0000

5.3000 550.0000

5.4000 750.0000

7.0000 800.0000

6.3000 850.0000

>> % GENERAR DIAGRAMA DE CAJA Y BIGOTE (BOX-PLOT) DE LAS TEMPERATURAS

>> boxplot(T) boxplot(DATOS(:,1:2)) 26 27 28 29 30 31 32 33 34 1 2

BOXPLOT DE LA TEMPERATURA  Y 

(24)

>> % construccion de histogramas y tabla de frecuencias

>> % construir histogramas de 7 clases para la variable de ESTATURA

>> hist(ESTATURA,7)

>> % construccion de histogramas y tabla de frecuencias

>> % construir histogramas de 7 clases para la variable de ESTATURA

>> hist(ESTATURA,7)

>> % calcular la frecuencia absoluta

26 27 28 29 30 31 32 33 34 1 2

BOXPLOT DE LA TEMPERATURA  Y 

T E M P E R A T U R A oC

1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9

0 1 2 3 4 5 6

Distribucion de frecuencias de la estatura

(25)

>> f=hist(ESTATURA,7);

>> %calcular frecuencia relativa

>> fr=f/suma(f)

Undefined function 'suma' for input arguments of type 'double'.

Did you mean:

>> fr=f/sum(f)

fr =

0.0952 0.0476 0.2381 0.1429 0.1429 0.2857 0.0476

>> %frecuencia acumulada

>> F_acum=cumsum(f)

F_acum =

2 3 8 11 14 20 21

>> % frecuencia relativa acumulada

>> Fra=F_acum/sum(f)

Fra =

(26)

>> Tabla_de_frecuencia=[f' fr' F_acum' Fra']

Tabla_de_frecuencia =

2.0000 0.0952 2.0000 0.0952

1.0000 0.0476 3.0000 0.1429

5.0000 0.2381 8.0000 0.3810

3.0000 0.1429 11.0000 0.5238

3.0000 0.1429 14.0000 0.6667

6.0000 0.2857 20.0000 0.9524

Referencias

Documento similar

The general idea of the language is to “thread together,” so to speak, existing systems that parse and analyze single web pages into a navigation procedure spanning several pages of

Government policy varies between nations and this guidance sets out the need for balanced decision-making about ways of working, and the ongoing safety considerations

No obstante, como esta enfermedad afecta a cada persona de manera diferente, no todas las opciones de cuidado y tratamiento pueden ser apropiadas para cada individuo.. La forma

The program is based on the following pillars: (a) students become the main agents of their learning by constructing their own knowledge; (b) the teacher must be the guide to

This paper reviews the current available bone targeting drug delivery systems, focusing on nanoparticles, proposed for osteoporosis treatment.. Bone targeting delivery systems is

The Dwellers in the Garden of Allah 109... The Dwellers in the Garden of Allah

The encoder currently connected or for which type the data currently loaded are valid, is indicated here for the information of the user,R. The following can

Finally, experiments with solar [17–34], atmospheric [35–45], reactor [46–50], and long-baseline accelerator [51–59] neutrinos indicate that neutrino flavor change through