Alternative for a for loop. How would I write this code without using a for loop?
Afficher commentaires plus anciens
function approx = approxCosineFunction(x, t)
approx=1;
for i=1:1:t-1
addterm = (-1)^i*(x^(2*i))/factorial(2*i);
approx = approx + addterm;
end
end
2 commentaires
Matt J
le 2 Nov 2017
There are already no for loops in the code that you've shown.
John Barber
le 2 Nov 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!