how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....
3 views (last 30 days)
Show older comments
how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....
2 Comments
Answers (1)
KSSV
on 2 Aug 2020
It is your Home work..you have to do it. Do the following.
- Read about for loop.
- Fix the value of n, to run a loop.
- You can decide the sign -, + by using mod.
- Intialize sum = 0, and add every time to loop (-1)^i*(1/j)
4 Comments
Vladimir Sovkov
on 2 Aug 2020
Two possibilities:
- 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.
- 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
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!