cs102 lab6


https://maths.nuigalway.ie/~gettrick/teach/cs102/2024/labs/l6.html




This lab follows the setup of the previous lab (lab 5), but asks for a different calculation: Consider the (20x20) array of numbers here. Lets say this represents a matrix A of distances (in kilometers) between cities. Note that A is symmetric A(i,j) = A(j,i) and all its diagonal elements are zero. Suppose Vladimir from city i and Petra from city j want to meet up in some third city k (i, j and k are all different). They plan to leave their home town at the same time, and hope to arrive in city k at approximately the same time. For this reason, they want k to be chosen so that its distance from each of them is approximately the same, or as close as they can get to that. In other words, they want to minimize the magnitude of A(i,k) - A(j,k). (Note that they do not care about the actual values of A(i,k) or A(j,k) on their own.) Given i and j, write a program in PYTHON that determines what k should be. (In PYTHON you can store the matrix as a list of lists). Do not worry in your program about "reading in" A: Just hard-wire it in to the code. You should read in from the user the two cities (i and j) where Vladimir and Petra live. From your program, calculate the answer for

(and submit these answers in the comment box, along with your uploaded .py/.ipynb file).

© University of Galway