[Tutor] Trigonometric Functions in Python
DL Neil
PyTutor at danceswithmice.info
Mon May 25 22:07:46 EDT 2020
On 26/05/20 1:24 PM, boB Stepp wrote:
> Greetings April!
>
> On Sun, May 24, 2020 at 08:09:32PM -0400, April Morone wrote:
>> I signed up for the ITP100 Software Design (Python Programming) class for
>> this Summer. I have been working ahead through the book, but came
>> across an
>> issue with understanding something within Chapter 4 of the book
>> "Python for
>> Everybody: Exploring Data in Python 3" that is by the author Charles
>> Severance on page 45. Please explain for me how the following checks the
>> result of the conversion from degrees to radius to get
>> 0.7071067811865476
>> to see if the result is correct:
>>
>> math.sqrt(2) / 2.
>>
>> of the following:
>>
>>>>> degrees = 45
>>>>> radians = degrees / 360.0 * 2 * math.pi
>>>>> math.sin(radians)
>> 0.7071067811865475
>
> It is not totally clear to me exactly where you are not following things.
> It appears that it is the math, not the Python, which is unclear.
>
> By definition there will be 2 * pi radians in a full 360 degree angle, or
> pi radians for a half-circle angle. So 2 * pi radians = 360 degrees. So
> the line above might be rewritten:
>
> 2 * pi radians = 360 degrees
> 1 radian = 360/(2 * pi) degrees, or
> 1 degree = (2 * pi)/360 radians
>
> Does that make sense? So if 1 degree is the above, then 45 degrees would
> be:
>
> 45 * 1 degrees = (45 * 2 * pi)/360 radians, which simplifies to
> 45 degrees = pi/4 radians
>
> For a right triangle (implying a 90 degree angle) if one of the other two
> angles is 45 degrees then the other one will be, too, as the sum of all
> angles in a triangle must add up to 180 degrees. And the two 45 degree
> angles imply that the height of the right triangle will equal the width of
> the triangle.
>
> Using the Pythagorean Theorem which states that the sum of the squares of
> the sides must equal the square of the hypotenuse, or, if the width of the
> side is x, the height y and the hypotenuse length r, then
>
> x**2 + y**2 = r**2
>
> If we arbitrarily choose x = y = 1 for our 45 degree angle we would have:
>
> r**2 = 1**2 + 1**2
> r**2 = 2, and taking the square root of both sides:
> r = sqrt(2)
>
> Sine of an angle = height / hypotenuse, so
>
> sine(45 degrees) = 1/sqrt(2)
>
> If you multiply the top and bottom by sqrt(2) you get
>
> sine(45 degrees) = (sqrt(2) * 1) / (sqrt(2) * sqrt(2)) = sqrt(2) / 2
>
> If you divide that out you will get the result you stated.
>
>
>> How does the following check the result of the above conversion from
>> degrees to radius to see if the result is correct?
>>
>>>>> math.sqrt(2) / 2.0
>
> See above. Does any of this help? Note that what I wrote above is not
> actual
> Python code statements. I am just trying to help you see the math.
I think boB knows all the angles [joke], but like him, I wasn't sure how
best to respond.
If 'trig' is the source of your problems (as opposed to Python), then
perhaps a little research around the web would be helpful, eg
https://www.mathsisfun.com/sine-cosine-tangent.html That page helpfully
illustrates the idea of extending your single angle into a right-angled
triangle (per @Alan) and thereafter the relationships between sine,
cosine, and tangent - which will bring you to the point of being able to
take the sine result (above) and checking its relationship with the
others, to prove correctness.
When my memory is (mathematically) insufficient http://wolframalpha.com/
will frequently perform a rescue.
NB I didn't look, but Sal Khan's Academy may offer suitable 'revision'
topics...
--
Regards =dn
More information about the Tutor
mailing list