Answered step by step
Verified Expert Solution
Link Copied!

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

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Management

Authors: Gareth Jones, Jennifer George

9th Edition

0077718372, 978-0077718374

More Books

Students also viewed these Programming questions

Question

What courses does he/she teach?

Answered: 1 week ago

Question

Code for building finance manger app in java angular

Answered: 1 week ago