Fundamental question: How does MATLAB calculate the sine function?

13 views (last 30 days)
Since it is a built-in function there is little information provided and many online Q/A's have to do with using the sine function for particular applications not the fundamental code-level evaluation of the function.
I imagine the modulo function is used to convert a wide range of angles to the 0:2*pi or -pi:pi range prior to sine function mathematics.
If a series expansion is used, what is the highest order term used? If a look-up table is used, what is the number of table entries within the above range?
These questions come up in our discussion of error propagation of functions.
Thank you, Ron LaFleur, Clarkson University

Accepted Answer

Steven Lord
Steven Lord on 15 Mar 2017
You may be interested in this article from Cleve.
  1 Comment
Ronald LaFleur
Ronald LaFleur on 15 Mar 2017
Thank you for referencing the relevant article.
I have been using a similar algorithm that builds the series on prior terms so no factorials or power functions are needed. With this series approach I can use a 'duals' number representation with a center value and an error vector of any dimension and basic arithmetic (addition,subtraction,multiplcation,division) for this datatype to evaluate the sine-of-duals function.
The clue from the Cleve's article is to use range reduction, to narrow x as much as possible so the effective x magnitude is not large and the series 'converges' in a lower number of terms. The pi/4 range is necessary otherwise there a significant cost to include the higher terms. This cost is even more significant when the error vector and its interaction are carried into the arithmetic.
The article gives me a much better idea of what to do to get acceptable results (lowest-range reduction, series expansion).

Sign in to comment.

More Answers (1)

James Tursa
James Tursa on 15 Mar 2017
MATLAB doesn't publish all of their function algorithms, but I would guess it would be range reduction followed by a rational function approximation rather than a series expansion. The range reduction is not trivial. E.g., see this link:
https://www.mathworks.com/matlabcentral/answers/195965-taylor-series-cosx-function
  1 Comment
Ronald LaFleur
Ronald LaFleur on 15 Mar 2017
Thank you for the information. Based on your reference, I plan to use the two-step process (floor, remainder) rather than the mod function. Based on other answers, the range reduction has to be done well to take advantage of a series expansion with a lower number of terms.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!