sum of complicated numbers
2 ビュー (過去 30 日間)
古いコメントを表示
how can I add these numbers
1:2:101 , 1:-2:101
3 件のコメント
Image Analyst
2022 年 2 月 15 日
Do you mean he had said previously
1 -3 5 -7 9 -11 13 -15 17 -19 21
and then changed it to the null vector 1 : -2 : 101 ?
回答 (1 件)
DGM
2022 年 2 月 15 日
編集済み: DGM
2022 年 2 月 15 日
Consider the reduced example.
N = 21;
n = 1:2:N
n = (1-2*mod((n-1)/2,2)).*n
s = sum(n)
If you must absolutely do it with a loop, you can use the above arithmetic to generate the sequence.
EDIT:
The revised question does suggest its own method which works just as well:
N = 21;
n = sum([1:4:N -(3:4:N)])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Electrical Block Libraries についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!