struktura prezentacije dvodimenzionalni nizovi (matrice) - programming language c - english language...

46
Struktura prezentacije Struktura prezentacije DVODIMENZIONALNI NIZOVI DVODIMENZIONALNI NIZOVI (MATRICE) (MATRICE) - Programming language C - English language - Mathematics 1. Čas - Opšti pojmovi, primeri i uvežbavanja 2. Čas - Osnovne operacije i njihova primena 3. Čas - Utvrđivanje, samostalna provera i smernice za dalji r Tehnička škola Takovska, 22 Pirot www.tehnickaskola-pirot.edu.yu

Upload: matilda-mcdaniel

Post on 29-Jan-2016

235 views

Category:

Documents


2 download

TRANSCRIPT

Struktura prezentacijeStruktura prezentacije

DVODIMENZIONALNI NIZOVIDVODIMENZIONALNI NIZOVI(MATRICE)(MATRICE)

- Programming language C- English language

- Mathematics

1. Čas - Opšti pojmovi, primeri i uvežbavanja

2. Čas - Osnovne operacije i njihova primena

3. Čas - Utvrđivanje, samostalna provera i smernice za dalji rad

Tehnička škola

Takovska, 22 Pirot

www.tehnickaskola-pirot.edu.yu

ČAS 1.ČAS 1. DEFINICIJA DVODIMENZIONALNOG

NIZA - M A T R I C E

- Primeri matričnog (tabelarnog) uređenja Primeri matričnog (tabelarnog) uređenja podataka i primene ovakve strukturepodataka i primene ovakve strukture

- Matematička definicija strukture i - Matematička definicija strukture i funkcionalnostifunkcionalnosti

- Primena u vežbi na engleskom jeziku- Primena u vežbi na engleskom jeziku

- Matrice u programiranju- Matrice u programiranju

(Programski jezik C)(Programski jezik C)

NextNextBackBack

Primeri (Examples)Šahovska tabla

NextNextBackBack

x 1 2 3 4 5 6 7 8 9 10

1 1 2 3 4 5 6 7 8 9 10

2 2 4 6 8 10 12 14 16 18 20

3 3 6 9 12 15 18 21 24 27 30

4 4 8 12 16 20 24 28 32 36 40

5 5 10 15 20 25 30 35 40 45 50

6 6 12 18 24 30 36 42 48 54 60

7 7 14 21 28 35 42 49 56 63 70

8 8 16 24 32 40 48 56 64 72 80

9 9 18 27 36 45 54 63 72 81 90

10 10 20 30 40 50 60 70 80 90100

Tablica množenja NextNextBackBack

Matrični displej NextNextBackBack

Tastatura NextNextBackBack

I ko zna koliko još ... NextNextBackBack

Navedite bez velikog razmišljanja svoj primer matrične (tabelarne) strukture podataka iz okoline !

na primer:na primer: Kalendar, Ukrštene reči, Lavirint,Periodični sistem hemijskih elementa, Šare pirotskog ćilima, ...

Brainstorming !!! (Ideas, please…)

Need HELP ? Click here !!!

NextNextBackBack

Poveži sa nečim što već znaš !Ređanjem više jednodimenzionalnih nizova podataka istih dimenzija i tipa podataka jedan do drugog dobijamo i drugu dimenziju .

a1

a2

a3.

.

.

an

a1

a2

a3.

.

.

an

a1

a2

a3.

.

.

an

a1

a2

a3.

.

.

an

.

.

..

.

.

.

.

.

..

.

.

.

I dim

enzija

II dimenzija

.

.

..

.

.

.

NextNextBackBack

Struktura, osnovni pojmovi

a11 a12 a13 a14 a15 ... a1n

a21 a22 a23 a24 a25 ... a2n

a31 a32 a33 a34 a35 ... a3n

... .. ... ... ... ... ...

am1 am2 am3 am4 am5 ... amn

aij

Redovi (ROWS)

Kolone (COLUMNS)

Elementi matriceElementi matrice - presek svakog reda (i) i svake kolone (j)

NextNextBackBack

Terminologija (Basic terms)

(Rows) Redovi ili vrste su horizontale u matrici odnosno nizovi elemenata čiji je prvi indeks jednak

(Columns) Kolone su vertikale u matrici odnosno nizovi elemenata čiji je drugi indeks jednak

(Size) Veličina odnosno dimenzije matrice određene su brojem redova (m) i brojem kolona (n) i zapisuje se kao m x n

NextNextBackBack

Skraćeni zapis matrice (Mathematics)

A = A = {{aaijij}}, i=1,m ; j= 1,n, i=1,m ; j= 1,n

NextNextBackBack

Vežba - PREPOZNAJ SEBE U MATRICI

Spojiti klupe i formirati matricu dimenzija 5x6 (ili sličnu)

a) Svaki učenik na pratećem obrascu u zadatim poljima

upisuje svoju poziciju u učionici <click za

dalje>

b) Svaki učenik na pratećem obrascu u zadatom polju

upisuje svoju visinu u cm <click za

dalje>

c) Neka ustanu svi učenici zadatog reda/kolone

redom (1, 4, 2, 3, 5) <click za dalje>

a) Neka ustanu redom svi učenici kod kojih je

i>j, i<j, i=j NextNextBackBack

Vežba - OSMOSMERKA

U narednoj vežbi uvežbavaju se osnovni pojmovi vezani za strukturu matrice. Vežba je na engleskom jeziku i podrazumeva znanja na temu "Nepravilni glagoli" odnosno njihovi oblici u infinitivu, prošlom vremenu i prošlom participu.

Rezultate vežbe učenici upisuju u odgovarajuća polja na priloženom obrascu za praćenje časa. Ovi rezultati koriste se i u narednim vežbama.

NextNextBackBack

Word Search Puzzle - Irregular verbs

1 2 3

1 ATE GOTTEN

TAUGHT

2 BROKEN

GROWN

THOUGHT

3 DONE LET TORE

4 DRANK RIDDEN

WORE

5 FED SLEPT WRITTENFind the following irregular verbs in the MATRIX to the right.

•Give a list of (i,j) positions of the elements in the matrix.

•state whether the verb is in the past or past participle form (II and III column in the list of irregular verbs)

• supply the missing two.

Example

•Been b (4,1) e (3,2) e (2,3) n (1,4)

•been –past participle

•be - was/were - been

1 2 3 4 5 6 7 8 9 10

1 L D C N X K M A A T

2 L N E D D I R K A H

3 O E X F N I T U S G

4 B K N A R D G E I U

5 T O R E A H P C J O

6 W R I T T E N O D H

7 Z B U P L T W O V T

8 W O R E E A O D H S

9 R P S L E H R G E U

10 O C C S S K G E C B

<click> <clear>

NextNextBackBack

Word Search Puzzle - SOLUTION

1 2 3

1 ATE GOTTEN

TAUGHT

2 BROKEN

GROWN

THOUGHT

3 DONE LET TORE

4 DRANK RIDDEN

WORE

5 FED SLEPT WRITTEN

1 2 3 4 5 6 7 8 9 10

1 L D C N X K M A A T

2 L N E D D I R K A H

3 O E X F N I T U S G

4 B K N A R D G E I U

5 T O R E A H P C J O

6 W R I T T E N O D H

7 Z B U P L T W O V T

8 W O R E E A O D H S

9 R P S L E H R G E U

10 O C C S S K G E C B

ATE (8,6) (7,6) (6,6)

BROKEN(7,2) (6,2) (5,2) (4,2) (3,2) (2,2)

DONE(6,9) (6,8) (6,7) (6,6)

DRANK(4,6) (4,5) (4,4) (4,3) (4,2)

FED(3,4) (2,3) (1,2)

GOTTEN(9,8) (8,7) (7,6) (6,5) (5,4) (4,3)

GROWN(10,7) (9,7) (8,7) (7,7) (6,7)

LET(9,4) (8,5) (7,6)

RIDDEN(2,7) (2,6) (2,5) (2,4) (2,3) (2,2)

SLEPT(10,4) (9,4) (8,4) (7,4) (6,4)

TAUGHT(1,10) (2,9) (3,8) (4,7) (5,6) (6,5)

THOUGHT (7,10) (6,10) (5,10) (4,10) (3,10) (2,10) (1,10)

TORE(5,1) (5,2) (5,3) (5,4)

WORE(8,1) (8,2) (8,3) (8,4)

WRITTEN (6,1) (6,2) (6,3) (6,4) (6,5) (6,6)(6,7)

NextNextBackBack

Matrice u programskom jeziku C

Deklaracija matrice:tip Ident[m][n]; tip - tip podataka (Data

type)elemenata matriceIdent - ime matricem - broj redovan - broj kolona

Primer:int M[5][6]; ili uz inicijalizaciju (dodelu

početnihvrednosti elemenata matrice):

float R[2][3] = { {2.3,4,0.45}, {3,3.4,5.6} };NextNextBackBack

Matrice u programskom jeziku CSpecifičnost programskog jezika C:

indeksi redova i kolona su iz opsega i = 0 . . m-1 (ukupno m)j = 0 . . n-1 (ukupno n)

Primer:Ukoliko je deklarisana matrica na sledeći

način:int M[5][6];

to znači da se indeksi vrste i kolone kreću u sledećim granicama:

i = 0 .. 4, j = 0 .. 5NextNextBackBack

Pristup elementima u matrici

Pristup elementima ("upotrebi ili dodeli vrednost") matrice je operacija u kojoj koristimo određeni element/e matrice sa ciljem korišćenja njegove vrednosti u drugim naredbama/funkcijama ili dodele vrednosti datom elementu.

Ident[i][j]

Primer:int M[5][6], a, b=4;M[0][3] = b;M[2][5] = 25;a = M[0][3] + 2;if( a> M[2][5])printf("Vrednost promenljive A je

veća !!!);

NextNextBackBack

Vežba - Napiši svoj program

Svoje rezultate iz osmosmerke prikazati programski po ugledu na zadati primer. Svoj program zapisati u zadato polje na pratećen obrascu.

#include<stdio.h>

void main() {

int A[10][10] = {{...} ...};

printf("%d %d ...", A[4][5], A[4][6], ...);

printf("Infinitiv glagola je: ....");

printf("Zadati glagol ... je iz 2/3

kolone.");}

NextNextBackBack

ČAS 2 - OBILAZAK MATRICEPodsetimo se obilaska ("prolaza kroz") jednodimenzionalnih nizova za početak.Obilazak matrice je osnovna operacija u matrici. Realizuje se nadogradnjom algoritma obilaska nizova.Naučimo i uvežbajmo načine obilaska "red po red" i "kolonu po kolonu".Analizom primera upotrebe operacije obilaska matrice uočiti koje složenije operacije u matrici se zasnivaju na obilasku.

NextNextBackBack

Obilazak jednodimenzionalnog niza (da počnemo od poznatog)

• Ova operacija u nizu izvodi se tako što se redom pristupa svim elementima niza počevši od prvog prema poslednjem

• Pristup elementu niza znači korišćenje vrednosti datog elementa niza ili dodelu vrednosti datom elementu u nizu

• Pristup elementu je operacija koja se ponavlja onoliko puta koliko ima elemenata u nizu

NextNextBackBack

Algoritamska / programska realizacijaPonavljanje pristupa elementu niza realizujemo brojačkim ciklusom (petljom)

Primer:

for(i=0; i<n; i++)

Niz[i] = i;

ili

for(i=0; i<n; i++)printf("%d", Niz[i]);

j = 1, M

Niz[i] = i

j = 1, M

Niz[i]

NextNextBackBack

Vežba - Obilazak niza podataka

Opis algoritma uz demonstraciju u I redu učenika:

1. Prvog učenika u nizu proglašavamo najvišim in on stoji a ostali sede

2. indeks niza (brojač) počinje od vrednosti 2 i završava se brojem učenika u I redu

3. Upoređuju se visine do sada najvišeg učenika (koji stoji) i onaj do kog se stiglo indeksom (brojačem u petlji) koji takođe ustaje

4. Ukoliko je dostignuti učenik viši od do sada najvišeg on ostaje da stoji

5. indeks niza (brojač) se uvećava za 1 i ponavlja se korak 3 i 4

6. ukoliko je dostignut poslednji, učenik koji stoji je najviši i nalazi se na zadatoj poziciji

NextNextBackBack

Vežba - "Play roles & demonstrate"

Using the following questions, answers and statements demonstrate the previously described algorithm.

1. My position in the array is ___ 2. I am ___ cm tall.3. What is your position in the array?4. How tall are you?5. I am taller and from now on : “I am the tallest in the array

so far”6. Who is the next student in the array to compare with?7. Did we reach the end of the array?8. I am the tallest in the array. I am ___ cm tall and my

position is ___ in the array! NextNextBackBack

Brainstorming !!! (Ideas, please!)

1. Kako proširiti prethodni algoritam da bi odredili najvišeg učenika u celom odeljenju (klupe čine matricu)?

2. Koliko puta treba ponoviti prethodni algoritam za celu matricu?

3. Šta i kako iskoristiti za to ponavljanje u programskoj realizaciji?

NextNextBackBack

Obilazak matrice

a11

a21

a31.

.

.

am1

a12

a22

a32.

.

.

am2

a13

a23

a33.

.

.

am3

a1n

a2n

a3n.

.

.

amn

.

.

..

.

.

.

a11

a21

a31.

.

.

am1

a12

a22

a32.

.

.

am2

a13

a23

a33.

.

.

am3

a1n

a2n

a3n.

.

.

amn

.

.

..

.

.

.

"Column by column"<click>

"Row by row"

<click>

U svakom prolazu kroz red indeks elemenata tog reda se kreće od 1 do n. Prelaskom u naredni red indeks elemenata se vraća na vrednost 1 i ponovo kreće do n.

U svakom prolazu kroz kolonu indeks elemenata te kolone se kreće od 1 do m. Prelaskom u narednu kolonu indeks elemenata se vraća na vrednost 1 i ponovo kreće do m.

NextNextBackBack

Primer upotrebe obilaska matrice(Tablica množenja)

"red po red"main () {int i, j, M[10][10];for(i=0; i<10; i++)

for(j=0; j<10; j++)

M[i][j] = i*j;

"kolona po kolona"main () {int i, j, M[10][10];for(j=0; j<10; j++)

for(i=0; i<10; i++)

M[i][j] = i*j;

Na primeru formiranja vrednosti elemenata matrice M(10,10) po ugledu na tablicu množenja demostrirati dva načina obilaska matrice: "red po red" i "kolonu po kolonu"

NextNextBackBack

Koristeći dva učenika kao indekse i i j izvršiti prozivku učenika prethodno opisanim obilascima matrice! Učenici "indeksi" stoje sa strane (i) i ispred klupa (j) i prate promene koje u algoritmu čine brojačke promenljive i i j diktirane spoljnom i unutrašnjom for petljom. "Prozvani" učenik izgovara svoju visinu u cm. Uočiti i komentarisati dinamiku brojača unutrašnje i spoljne for petlje.

Algoritmi obilaska matrice Demonstracija u odeljenju-matrici

NextNextBackBack

Vežba: Primer obilaska matrice(Broj pojavljivanja podatka u matrici)

Algorithm counting the given data P in the matrix using matrix iteration“row by row”

1.Set the starting value of the counter No=0 (No=0 at the beginning means that maybe there is no given data in the matrix)

2.Set the row counter of the matrix as i=1 and increase it in every iteration for 1 increment (i). If the bordering value is exceeded, go to the step 7. (i= n+1- the number of rows in the matrix + 1)

3.Set an element counter within the row j=1 and increase it in every iteration for 1 increment (j). If the bordering value is exceeded , go to the step 6. (j=m+1 – the number of columns in the matrix plus 1)

4.Compare the achieved element of the matrix with the given data M (i,j)=P? If that is the case, increase the number of occurrence - Increment (Br)

5.Go back to step 3.6.Go back to step 2.7.Show the value of Br which represents the number of

occurrence of the data N in the matrix.Answer the question:What could we count in the classroom using this method?

Choose the most appropriate examples.

NextNextBackBack

ČAS 3. - Proveri šta si naučio!

Obnovi stečena/uvežbana znanja i usvojene pojmove sa prethodnih časova radeći na tekstu na engleskom jeziku. Prepoznaj celine u kojima se ne snalaziš dobro! Vrati se u ličnom pratećem materijalu i podseti se rešenja!Pokušaj da prepoznaš najbitnije i kritički se osvrneš na moguće primene.Zapitaj se "Šta sledi?" i pokušaj da nađeš prave odgovore!

NextNextBackBack

Pročitaj pažljivo tekst!

Two-dimensional data arrays- MATRICES

Data are usually organized in the form of a table which suits the given data best. There is a rich variety of examples in our surroundings: school register, weekly attendance records, charts of weekly city temperatures, calendar, chess, “Reveal the pairs” game, results of laboratory measurements, etc.

If we take several one–dimensional data arrays of the same length (number of elements) and write them one below the other, thus forming a table, we get the so called two-dimensional array or “an array of arrays” which is usually referred to as a matrix. The number of one-dimensional arrays (rows) represents the first dimension of the matrix and the number of elements in each of the arrays (column) represents the second dimension of the matrix. These numbers mxn are called matrix dimensions.

The position (place) of the data within the matrix is determined by the number of the row and the number of the column of the particular data (intersection of the given column and the given row). These numbers are usually referred to as row subscript and column subscript according to the element subscript in one-dimensional array.

All the matrix elements represent the data of the same type (uniformity of data type) and they carry the same name which is at the same time the name of the whole matrix. (uniqueness of the identifiers)

NextNextBackBack

Matrix of the dimensions mxn can be mathematically expressed in the following way:

or the short form A=(aij), i=1,m j=1,n.

The basic operation that can be performed in the matrix is the so called matrix iteration or passing round matrix. Essentially, this operation represents the access to all matrix elements “row by row” or “column by column”.

In programming matrix iteration is used for solving the following tasks which are usually found when solving complex problems:

– Assigning values to matrix elements (using the keyboard or the assigning operator “=”)

– Matrix illustration– Searching for the given data in the matrix– Determining of the smallest/biggest matrix element– Determining of sum/average value of the matrix elements– Row/column sorting in the matrix

"Column by column""Row by row"

NextNextBackBack

Test - Answer the Questions!

Odgovori na sledeća pitanja na osnovu prethodno pročitanog teksta i sadržaja na slajdovima.

(Umesto testa na narednim slajdovima moguće je iskoristiti interaktivnu verziju testa u prilogu!)

NextNextBackBack

Inetaktivni test (FLASH)

Test - Part I1. How do we call the horizontal and vertical wholes in a matrix?2. What determines the position of every element in a matrix?3. Matrix elements are data of the __________ data type.4. Element subscripts in the matrix are ________ which determine

in which ________ and which _______ the given element is positioned.

5. Matrix dimensions are determined by (circle all the correct answers):

a) The values of the neighboring elements in the matrixb) The number of columns in the matrixc) The position of elements in the bottom right corner of the matrixd) The number of rows in the matrixe) Element inscription order

6. What does the uniformity of data type in a matrix mean?7. What determines a specific name (identifier) of every matrix

element?8. If the matrix dimensions are mxn, what is the spectrum in

which subscript of column j and subscript of row i occurs?

NextNextBackBack

Test - Part II9. What is the short form of matrix in mathematics?10. Matrix iteration can also be called _________ matrix.11. In what ways can we perform matrix iteration?12. Which of the following examples of practical usage of matrix is

not an adequate one and why?a) Chessb) Multiplication tablec) Winning lottery numbersd) Calendar

13. State some examples of “matrix iteration” which you can use for more complex operations.

14. How many elements are there in Amxn matrix?15. In which part of the matrix are the elements for whose

subscripts i=j?16. Elements of the same matrix row have the same subscript j.

Yes / No?

NextNextBackBack

Test - Part III17. I’m 194 cm tall and I am __________ in the array. (Circle the correct

answer) a) tallest b) the tallest c) taller18. The position (place) of the data within the matrix is ___________ by

intersection of the given column and the given row. (Circle the correct answer) a) determination b) determines c) determined

19. If we take several one–dimensional data arrays of the same length and write them one below the other, we get the so called ________________.

20. Is the following sentence grammatically correct? Why / Why not? Data is usually organized in the form of a table which suits the given data best.

21. The number of elements in each of the arrays represents the second dimension of the matrix and it is called column / colon. Circle the correct answer.

22. What’s the plural form of the noun matrix?

NextNextBackBack

Part I - CORRECT ANSWERS1. Horizontal = ROWS Vertical = COLUMNS2. ROW SUBSCRIPT AND COLUMN SUBSCRIPT3. Matrix elements are data of the SAME data type.4. Element subscripts in the matrix are NUMBERS which

determine in which ROW and which COLUMN the given element is positioned.

5. Matrix dimensions are determined by (circle all the correct answers):

a) The values of the neighboring elements in the matrixb) The number of columns in the matrixc) The position of elements in the bottom right corner of the

matrixd) The number of rows in the matrixe) Element inscription order

6. All the matrix elements represent the DATA OF THE SAME TYPE.

7. The NAME of the WHOLE MATRIX.8. j = 1 . . m i = 1 . . n

NextNextBackBack

Part II - CORRECT ANSWERS

9. A=(aij), i=1,m j=1,n

10. Matrix iteration can also be called PASSING ROUND MATRIX .11. “row by row” or “column by column”12. Which of the following examples of practical usage of matrix is not

an adequate one and why?a) Chessb) Multiplication tablec) Winning lottery numbers - one dimensional arrayd) Calendar

13. Assigning values to matrix elements (using the keyboard or the assigning operator “=”)

Matrix illustrationSearching for the given data in the matrixDetermining of the smallest/biggest matrix elementDetermining of sum/average value of the matrix elementsRow/column sorting in the matrix

14. m x n15. Main diagonal16. Elements of the same matrix row have the same subscript j. Yes /

No ?

NextNextBackBack

Part III - CORRECT ANSWERS

17. I’m 194 cm tall and I am the tallest in the array. (Circle the correct answer) a) tallest b) the tallest c) taller

18. The position (place) of the data within the matrix is determined by intersection of the given column and the given row. (Circle the correct answer) a) determination b) determines c) determined

19. If we take several one–dimensional data arrays of the same length and write them one below the other, we get the so called two–dimensional data arrays - matrix.

20. Is the following sentence grammatically correct? Why / Why not? Data is usually organized in the form of a table which suits the given data best.

The sentence is not correct because the noun data is in the plural form and it requires another form of the verb to be and that is are.

Data are usually organized in the form of a table which suits the given data best.

21. The number of elements in each of the arrays represents the second dimension of the matrix and it is called column / colon. Circle the correct answer.

22. MATRICES

NextNextBackBack

VEŽBA - Uklopi u celinu(Programiraj)

Koristeći delove programa "razbacane" po slajdu izborom i pravilnim ređanjem uklopi u program zadate namene:a) Prikaz elemenata matrice na ekranub) Sumu elemenata matrice obilaskom matrice "kolonu po kolonu"

NextNextBackBack

#include <stdio.h> (3)

main() { (9)

for(i=0; i<m; i++)(4)

for(j=0; j<n; j++) (12)

printf("%5d", A[i][j]);

(7)

printf("\n"); (11)

{ (10)}

(6)

int suma = 0; (13)

int i,j; (5)

} (8)

suma += A[i][j]; (2)

printf("Suma matrice =%d\n", suma); (1)

NextNextBackBack

#include <stdio.h> (3)

main() { (9)

for(i=0; i<m; i++) (4)

for(j=0; j<n; j++) (12)

printf("%5d", A[i][j]); (7)

printf("\n"); (11)

{ (10)

} (6)

int i,j; (5)

} (8)

Prikaz elemenata matrice na ekranu

NextNextBackBack

#include <stdio.h> (3)

main() { (9)

for(i=0; i<m; i++) (4)

for(j=0; j<n; j++) (12)

int suma = 0; (13)

int i,j; (5)

} (8)

suma += A[i][j]; (2)

printf("Suma matrice =%d\n", suma); (1)

Sumu elemenata matriceobilaskom matrice "kolonu po kolonu"

NextNextBackBack

Popuni evaluacioni Popuni evaluacioni formular!formular!

Hvala na iskrenim Hvala na iskrenim odgovorima!odgovorima!

NextNextBackBack

The end The end BackBack STOPSTOP