Is Matlab generally faster at computing polynomials or trigonometric functions?

2 views (last 30 days)
Hi, I’ve got a pretty complicated mathematical function involving a lot of sin, cos, square roots, etc and it is called a large number of times in the program which can lead to decently long runtimes. The exact value isn’t necessarily important, so I can approximate my function with a sufficiently accurate polynomial. Is this worth it in general? I.e. is matlab ‘faster’ at computing powers than it is at computing trigonometric functions?
  1 Comment
KSSV
KSSV on 7 Feb 2023
The mat libraries behind calculate Trigonometirc functions by approsimating it to a polynomial. Rememebr Taylor series. You need not to worry about time. Read about the functions tic and toc to find the time taken. Read about profile to check your code.

Sign in to comment.

Answers (1)

Rik
Rik on 7 Feb 2023
You mean you want to approximate your complicated function with many calls by a single polynomial? If that is possible with your data, that would indeed be faster, since a single polynomial calculation will be faster than many calculations put together.
To find a middle ground in terms of accuracy you could even considering determining a few domains of input ranges and compute the polynomial for each domain. That will be a trade-off between determining the polynomial and accuracy (since you obviously shouldn't compute a polynomial for every unique input).
If you need help with implementation, you should post your current function, along with reasonable example inputs.

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!