Problem 299. vectorization in N
For a given integer n (n>1), compute the sum f (i) (1 <= i <= n) where f (i) = 1 if n is odd and 2 otherwise.
Solution Stats
Problem Comments
-
3 Comments
@bmtran (Bryant Tran)
on 9 Feb 2012
could you give an example? it's kind of hard to figure out what you're asking for.
Julio
on 9 Feb 2012
sorry, f(i) = 2 if i = even
Rafael S.T. Vieira
on 9 Aug 2020
The problem is asking for the sum of a function from 1 to n, where every odd input outputs 1, and even input outputs 2.
Solution Comments
Show commentsProblem Recent Solvers272
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6231 Solvers
-
Back to basics 13 - Input variables
266 Solvers
-
Who is the smartest MATLAB programmer?
753 Solvers
-
694 Solvers
-
Create an index-powered vector
768 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!