15_matrices

15_matrices - Introduction to Computers and Programming JK...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computers and Programming JK Lecture 15 Recap Prof. I. K. Lundqvist Reading: Oct 7 2003 FK pp. 557-563, handout • Defining and Manipulating 1D Arrays • Representing 2D arrays as 1D arrays • Today – Multi-Dimensional Arrays – Matrices – Operations of Matrices – The Matrix Package Two-dimensional Arrays • Two indices needed to reference elements in the array Amsterdam Berlin London Madrid Paris Rome Stockholm Amsterdam 0 648 494 1752 495 1735 1417 Berlin 648 0 1101 2349 1092 1588 1032 London 494 1101 0 1661 404 1870 1807 Madrid 1752 2349 1661 0 1257 2001 3138 Paris 495 1092 404 1257 0 1466 1881 Rome 1735 1588 1870 2001 1466 0 2620 Stockholm 1417 1032 1807 3138 1881 2620 0 max_dist : constant type Distances 0 .. max_dist; type City is Rome, Stockholm); type distance_table (City, City) of Distances; inter_city : distance_table := traveled : distance_table := ( others => (others => 0) ); your_travel : distance_table; is range is array ( 494, 1101, 0, 1661, 404, 1870, 1807), ( 495, 1092, 404, 1257, 0, 1466, 1881), -- various constants used in data types := 40077; -- max distance on earth -- type declarations (Amsterdam, Berlin, London, Madrid, Paris, -- distances between various European cities -- Amst, Berl, Lond, Madr, Pari, Rome, Stock (( 0, 648, 494, 1752, 495, 1735, 1417), -- Amsterdam ( 648, 0, 1101, 2349, 1092, 1588, 1032), -- Berlin -- London (1752, 2349, 1661, 0, 1257, 2001, 3138), -- Madrid -- Paris (1735, 1588, 1870, 2001, 1466, 0, 2620), -- Rome (1417, 1032, 1807, 3138, 1881, 2620, 0)); -- Stockholm -- distances I have traveled between various cities Using 2-D Arrays variable, use both index values put(inter_city(Berlin, Rome); traveled (Stockholm, London) := 1807; • for from in Amsterdam .. Stockholm loop for to in Amsterdam .. Stockholm loop PUT(inter_city(from, to), width=>6); ; NEW_LINE; ; Multi-dimensional arrays ranges Nested loops are often used to process 2D arrays...
View Full Document

Page1 / 12

15_matrices - Introduction to Computers and Programming JK...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online