Is Matlab generally faster at computing polynomials or trigonometric functions?

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 commentaire

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.

Connectez-vous pour commenter.

Réponses (1)

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.

Catégories

En savoir plus sur Polynomials dans Centre d'aide et File Exchange

Produits

Version

R2020b

Réponse apportée :

Rik
le 7 Fév 2023

Community Treasure Hunt

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

Start Hunting!

Translated by