How to apply the sum function of a factorial equation without using the factorial function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anj
am 20 Okt. 2013
Kommentiert: Image Analyst
am 20 Okt. 2013
How do I use SUM and nested FOR loops to calculate the sigma notation of (2^i)/(i!) when i=0..20 without using the function factorial(i)?
I've tried
A=2^i
SUM(A)=0
for i=1:20
SUM(A)=SUM(A)+i
but this already doesn't work, and I cannot add the nested for loop of the factorial until I have this. How would this nested for loop look without using the factorial() function?
0 Kommentare
Akzeptierte Antwort
sixwwwwww
am 20 Okt. 2013
Dear Anj, do you need something like this:
i = 1:20;
val = sum(2.^i);
10 Kommentare
sixwwwwww
am 20 Okt. 2013
Yes you are right. But I used nested for loop because it was insisted by Anj to use nested for loop. Thanks for suggestions about 'i' as loop variable. I will try to avoid it although it is my habit to use 'i' as loop variable. Thanks a lot nevertheless
Image Analyst
am 20 Okt. 2013
You're right. I don't know why teachers have students ignore the best part of MATLAB (vectorization) when that is exactly the perfect opportunity to demonstrate it.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!