Answered step by step
Verified Expert Solution
Question
1 Approved Answer
To match people, companies use trigonometry. Assume you have a list of people (po. p... Pm]. we find the two different people who have
To match people, companies use trigonometry. Assume you have a list of people (po. p... Pm]. we find the two different people who have the smallest angle. The way we calculate this is to assume each person is a list (mathematically vector) of Os and 1s. We need three basic functions: inner product, magnitude, and cos. We assume two lists = [...]. = [30.31] of Os and 1s of the same length: inner_prod(x,y)=00+13++ mag(z) Vinner prod(1,1) For the last function (where we calculate the angle), we know that: cos(9) inner_prod(x,y) mag(z)mag(y) In class we learned that we can invert a function and the inverted function is denoted as f-. So we can: inner_prod(z,y) mag(z)mag(y) inner_prod(x,y) mag(x)mag(y) The math module has math.acos() for cos(). Further, Python returns & in radians. We have: #radians 180 degrees (29) Thus, to convert from radians to degree, you must multiply your answer by 10. The task is to write two functions. The match function takes a list of people p, where each person is a list of Os 1s, and returns all unique pairs with the angle in degrees. The function best match takes the result from match and retums the pair with the "best" match-the smallest degree. We can assume there's only one best match. Here is a run (with some extra output) for your perusal. cos(cos(0)) 1 people0 [[0,1,1],[1.0.0],[1.1.1]] 2 print(match(people0)) 3 print (best_match (match(people0))) gives an output 1 [[[0, 1, 1], [1, 0, 0], 90.0], [[0, 1, 1], [1, 1, 1], 35.26], 2 3 [[1, 0, 0], [1, 1, 1], 54.74]] 4 ([0, 1, 1], [1, 1, 1], 35.26) COS (24) (25) cos ( (26) (27) (28)
Step by Step Solution
★★★★★
3.30 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
import math def innerprodxy total0 for i in rangelenx totalxiyi return total def getMagx return in...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started