how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....

3 views (last 30 days)
how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....

Answers (1)

KSSV
KSSV on 2 Aug 2020
It is your Home work..you have to do it. Do the following.
  1. Read about for loop.
  2. Fix the value of n, to run a loop.
  3. You can decide the sign -, + by using mod.
  4. Intialize sum = 0, and add every time to loop (-1)^i*(1/j)
  4 Comments
Vladimir Sovkov
Vladimir Sovkov on 2 Aug 2020
Two possibilities:
  1. It is a homework indeed. This case I do not want to explain anything--it is a responsibility of their professor, not me; besides, we do not know what the professor wants from them exactly.
  2. It is not a homework. They just encountered this problem in their current work but their matrhematical background is not good enough to find the best solution. This case my answer is the most useful.
Vladimir Sovkov
Vladimir Sovkov on 2 Aug 2020
Moreover: one of the basic ideologies of Matlab is to avoid loops wherever possible. Hence, an advice to do it without a loop must be instructive for learning Matlab as well.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!