For any triangle:
![Chart Chart](/uploads/1/2/5/7/125754155/287977651.png)
Dev C++ Online
a, b and c are sides. C is the angle opposite side c |
If no errors occur, the cosine of arg (cos(arg)) in the range -1; +1, is returned. The result may have little or no significance if the magnitude of arg is large (until C11). Dev-C sine and cosine (too old to reply) Brad Woosley 2008-01-19 03:07:59 UTC. I attempted to make a program that will use the sine and cosine of a number, but is seams that the #s were switched. Can anyone tell me if I did something wrong. Bellow is the code relevant to this. The C cmath header file declares a set of functions to perform mathematical operations such as: sqrt to calculate the square root, log to find natural logarithm of a number etc. First of all, a cosine of 180 degrees should be equal to -1, so the result you got is right. Secondly, you sometimes can't get exact values when using sin/cos/tan etc functions as you always get results that are the closest to the correct ones. In your case, the value you got from sin is the closest to zero. Apr 20, 2014 C Practical and Assignment Programs-cos(x) series expansion In this video we will write a program to calculate cosx using the series expansion of cosx. This function is overloaded in and (see complex cos and valarray cos). Additional overloads are provided in this header ( ) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type ).
The Law of Cosines (also called the Cosine Rule) says:
c2 = a2 + b2 − 2ab cos(C)
It helps us solve some triangles. Let's see how to use it.
Example: How long is side 'c' ... ?
We know angle C = 37º, and sides a = 8 and b = 11
Put in the values we know:c2 = 82 + 112 − 2 × 8 × 11 × cos(37º)
More calculations:c2 = 44.44...
Take the square root:c = √44.44 = 6.67 to 2 decimal places
Answer: c = 6.67
How to Remember
How can you remember the formula?
Well, it helps to know it's the Pythagoras Theorem with something extra so it works for all triangles:
Pythagoras Theorem:
(only for Right-Angled Triangles)a2 + b2 = c2
(only for Right-Angled Triangles)a2 + b2 = c2
Law of Cosines:
(for all triangles)a2 + b2− 2ab cos(C) = c2
(for all triangles)a2 + b2− 2ab cos(C) = c2
So, to remember it:
- think 'abc': a2 + b2 = c2,
- then a 2nd 'abc':2ab cos(C),
- and put them together: a2 + b2 − 2ab cos(C) = c2
When to Use
The Law of Cosines is useful for finding:
- the third side of a triangle when we know two sides and the angle between them (like the example above)
- the angles of a triangle when we know all three sides (as in the following example)
Cosine Tables
Example: What is Angle 'C' ...?
The side of length '8' is opposite angle C, so it is side c. The other two sides are a and b.
Now let us put what we know into The Law of Cosines:
Put in a, b and c:82 = 92 + 52 − 2 × 9 × 5 × cos(C)
Now we use our algebra skills to rearrange and solve:
Subtract 25 from both sides:39 = 81− 90 × cos(C)
Swap sides:−90 × cos(C) = −42
Inverse cosine:C = cos−1(42/90)
In Other Forms
Easier Version For Angles
We just saw how to find an angle when we know three sides. It took quite a few steps, so it is easier to use the 'direct' formula (which is just a rearrangement of the c2 = a2 + b2 − 2ab cos(C) formula). It can be in either of these forms:
cos(C) = a2 + b2 − c22ab
cos(A) = b2 + c2 − a22bc
cos(B) = c2 + a2 − b22ca
Example: Find Angle 'C' Using The Law of Cosines (angle version)
In this triangle we know the three sides:
- a = 8,
- b = 6 and
- c = 7.
Use The Law of Cosines (angle version) to find angle C :
= (82 + 62 − 72)/2×8×6
![C++ C++](/uploads/1/2/5/7/125754155/710640630.jpg)
= 51/96
C= cos−1(0.53125)
Versions for a, b and c
Also, we can rewrite the c2 = a2 + b2 − 2ab cos(C) formula into a2= and b2= form.
Here are all three:
a2 = b2 + c2 − 2bc cos(A)
b2 = a2 + c2 − 2ac cos(B)
c2 = a2 + b2 − 2ab cos(C)
But it is easier to remember the 'c2=' form and change the letters as needed !
As in this example:
Example: Find the distance 'z'
The letters are different! But that doesn't matter. We can easily substitute x for a, y for b and z for c
x for a, y for b and z for cz2 = x2 + y2 − 2xy cos(Z)
Put in the values we know:z2 = 9.42 + 6.52 − 2×9.4×6.5×cos(131º)
Calculate:z2 = 88.36 + 42.25 − 122.2 × (−0.656...)
z2 = 210.78...
Cosine C Programming
Answer: z = 14.5
Dev C Cosine Worksheet
Did you notice that cos(131º) is negative and this changes the last sign in the calculation to + (plus)? The cosine of an obtuse angle is always negative (see Unit Circle).