Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Why can't I get an output when I am trying to find Cosine of 180 radians using Taylor series expansion.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sum= double(1);
sign=1;
for n=2:2:1000
sign = -sign;
form = ((Rad).^n)/factorial(n);
sum = sum + (sign*(form));
if form <= 0.000000001
break;
end
end
CosFormula = sum
3 Kommentare
Torsten
am 9 Feb. 2016
"Rad" is undefined.
Furthermore, you should not build x^n/n! anew in each step because you will arrive at Infinity/Infinity quite soon for Rad>1. Note that form_new = form_old*x^2/((2*n-1)*2*n).
What are you trying to calculate - cos(180) or cos(pi) ? Note that the argument in the Taylor series expansion is in radians, not in degrees.
Best wishes
Torsten.
Guillaume
am 9 Feb. 2016
Do not use sum or sign as variable names. They both are the names of frequently used matlab functions and having a variable with the same name means you can't use the functions anymore.
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!