MATLAB: How toncrease the accuracy of trigonometric functions

MATLABtrigonometric-function accuracy

The typical function "sin", "cos" or "tan" seems not accurate enough for me. How to improve it?
And the function "digits" didn't work in this case.
Example codes (The answers should be 0):
>> alpha = 1;
>> cos(alpha) * tan(alpha) – sin(alpha)
ans =
1.1102e-16
>> tan(alpha) – sin(alpha) / cos(alpha)
ans =
2.2204e-16
>> digits(256);
>> cos(alpha) * tan(alpha) – sin(alpha)
ans =
1.1102e-16
>> tan(alpha) – sin(alpha) / cos(alpha)
ans =
2.2204e-16

Best Answer

alpha = sym(1);
>> simplify(cos(alpha) * tan(alpha) - sin(alpha))
ans =
0
>> simplify(tan(alpha) - sin(alpha) / cos(alpha))
ans =
0
There is no realistic prospect of getting an exact 0 for these calculations when using finite binary floating point calculations. The problem is not the accuracy of the trig functions: the problem occurs for all finite representations http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Related Question