I import "math.h".
I can use the cos function,
but when I execute cos(0.321139585333178)
the result is 0.948876
If I use the calculator in Mac or use a normal calculator, the result is 0.999984292347418
Can anyone help me to solve that problem?
You're confusing degrees with radians.
cos(0.321139585333178 degrees) = 0.999984292
cos(0.321139585333178 radians) = 0.948876326
To convert from radians to degrees, multiply by 180/π.
To convert from degrees to radians, multiply by π/180.
Related
x = 60.0;
val = PI / 180.0;
ret = cos( x*val );
printf("The cosine of %lf is %lf degrees\n", x, ret);
Hi, I was self-studying about function in math.h then i tried to use COS fuction to find the cos of radius in the program . I try to find the explantion of this function that Why COS function requires adding Pi/180.0 in Cos function to calculate cos of radius properly . Thank you so much
If you check the documentation, you'll see that cos() accepts an angle in radians, not degrees. By multiplying your angle of 60 degrees by PI / 180.0, you're converting it to radians.
When I write on my calculator Cos45 I get a decimal number = 0.707
How do I produce such a number in C.
I tested this:
printf ("type a degree between 0 - 360:\n");
scanf ("%f",&float1);
printf ("cosphi = %f",cosf(float1));
but it gave an off number. It produced cosphi = 0.52
Your calculator is configured to compute trigonometric functions in degrees.
C's trig functions work in radians. (A full circle is 360 degrees, 2*pi radians.)
If you want to treat the input as degrees, you need to convert the value to radians before passing it to cosf(), by multiplying it by 180/pi.
I got it to work. Thanks a million :)
#include <stdio.h>
int main ()
//Convert Trigonometric Angles into Decimals and Radians.
//Radians are number of Radiuses that are wrapped around the circumference.
//Pi for half the circle, Radius is wrapped 3.14 times on 180 degrees. r2=d1 .
//Circumference = 2radius * Pi = Diameter * Pi = 2Pi * radius .
//KHO2016.no2. mingw (TDM-GCC-32) . c-ansi .
{
//Declare
float flp1, flp2, flp3, flp4, pi;
int int1;
//valuate
pi = 3.141592654;
int1 = 180;
//calculate
printf ("type a degree between 0 - 360 : ");
scanf ("%f",&flp1);
flp2=int1/flp1; // 180 is divided by desired angle
flp3=pi/flp2; // Pi is divided by the result of 180 / desired angle = Radians
flp4=cosf(flp3); // Result of Pi divided by Radians and fed into the Cosf Radian modulus
printf ("The Decimal value of Cosinus %.1f degrees = %.3f\n",flp1,flp4);
printf ("Angle typed in Radians = %f",flp3);
//Terminate
return 0;
}
As answer well by #Keith Thompson, the C function works in radians and so a degrees to radian conversion is needed.
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
float angle_radians = angle_degrees * (float) (M_PI/180.0);
Yet rather that directly scale by pi/180.0, code will get more precise answers, for angles outside a primary range, if code first does range reduction and then scales by pi/180.0. This is because the scaling of pi/180.0 is inexact as machine pi float pi = 3.14159265; is not exactly mathematical π. The radian range reduction, performed by cos(), is in error as the computed radian value given to it is inexact to begin with. With degrees, range reduction can be done exactly.
// Benefit with angles outside -360° to +360°
float angle_degrees_reduce = fmodf(angle_degrees, 360.0f);
float angle_radians = angle_degrees_reduce * M_PI/180.0;
sind() is a sine example that performs even better by reducing to a narrower interval. With angles outside the -45° to +45° range, there is benefit.
I have this equation its output using a sci calc is : 0.017... but when i run it in c its output is :0.84..
The input is 1
Equation is: sin(x) - x^4 + 1
float sinp(float p1)
{
float fop;
float ppowers;
printf("%f",p1);
ppowers = pow(p1,4);
fop = sin(p1)-ppowers+1;
return (fop);
}
is there a reason behind this like would it be because of rad or in degree?
I havent really used the sin or any math function of C that much so I don't really get whats wrong here. Google gave me .84 as an aswer but my calc gives me .017 which is really confusing since I need to get the same output with my calc.
Thank you all :)
In mathemtics and in all computer languages trigonometric functions work in radians. If you want to work in degrees you should make the conversion (or define your own sin_degrees function) like:
double sin_degrees(double degrees) {
return sin(degrees * (M_PI/180.0);
}
I am guessing google uses degrees as angle measure in sin, while c++ uses radians and that is the reason for the difference. To convert an angle in degrees to same value in radians to the following:
rad_angle = deg_angle * (PI / 180.0);
Where PI it the good old constant you know.
Imagine you have a computer, Computer B, that only has a tangent function and can only return accurate results on the tangent of an angle between 0 and 45 degrees. Given an angle, ø, greater than 45 degrees and less than 90, what mathematical operations could be performed to return an accurate tangent value? Also provide a detailed example.
I need some help on this. This tan problem is in terms of the coprocessor and FPTAN instruction. Any ideas?
This looks like homework, so as a hint: given a right angle triangle, if one angle is greater than 45 deg, then the other is less than 45 deg. Furthermore
cos(PHI) = sin(THETA)
sin(PHI) = cos(THETA)
If PHI and THETA are the angles in your triangle. I believe that should get you going.
Use the fact that 1/TAN(θ)=COT(θ)=TAN(π/2-θ).
In Silverlight, is there a way to determine the angle of a Line object? If I have a Line with coordinates of 0,0 - 30,80, is there a way to determine the angle, in degrees, that the line is running?
You could try finding the arc tangent using the Math.Atan function. You just need to find the atan of the (delta of) y-value over the (delta of) x-value.
The answer will be in radians and you will need to convert it to degrees (rads * (180f / Math.PI)).
An example of this would be something like:
double rads = Math.Atan((line.Y2 - line.Y1) / (line.X2 - line.X1));
double degrees = rads * (180f / Math.PI);
(Note: I've never used Silverlight and I'm just basing this off the docs, so this might be completely wrong... you can also use Math.Atan2(delta y, delta x) too...)