Using a for loop to compute a Taylor series of sine?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Aaron Zorzi
il 8 Ott 2015
Commentato: Esteban Gómez
il 20 Gen 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149870/image.png)
I understand while loops pretty well, but for loops always seem to throw me off. Can someone please help me? Thanks.
2 Commenti
James Tursa
il 8 Ott 2015
Please make an attempt and post your code, and then ask specific questions about it. Then we can comment on it and make suggestions.
Risposta accettata
Stalin Samuel
il 8 Ott 2015
%%sample code
prompt = 'Enter angle value between 0 to 2pi? ';
x = input(prompt)
prompt = 'Enter the no of terms? ';
N = input(prompt)
ty = 0;
for i = 1:N
ty = ty +((-1)^(i))*((x^(2*i+1))/(factorial(2*i+1)));%your calculations
end
fprintf(['actual value ' num2str(ty)]) %display the results
1 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!