how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....
3 ビュー (過去 30 日間)
古いコメントを表示
how can i write the code out for this 1-1/2+1/3-1/4+1/5-,.....
2 件のコメント
回答 (1 件)
KSSV
2020 年 8 月 2 日
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 件のコメント
Vladimir Sovkov
2020 年 8 月 2 日
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
2020 年 8 月 2 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!