Create a vector x with the elements
26 ビュー (過去 30 日間)
古いコメントを表示
Create a vector x with the elements x = (-1^n + 1/2*n -1 ) Add up the elements of the version of this vector that has 100 elements.
Can someone tell me how to do it?
2 件のコメント
Walter Roberson
2011 年 2 月 3 日
Is that (-1)^n ? Does the 1/2 apply to n or to (n-1) ? Is n a constant, or does it represent the index of the element? If it represents the index, should n start at 0 or at 1 ?
the cyclist
2011 年 2 月 3 日
If this is class homework, please say so and describe what you have tried on your own.
回答 (2 件)
Davide Ferraro
2011 年 2 月 3 日
You can use vector operations on the vector n with elements from 1 to 100:
x = (-1.^n + 1/2*n -1);
to create the x vector.
If you need to sum every element you can then use the SUM command:
sum(x)
0 件のコメント
Barnali
2023 年 8 月 21 日
編集済み: DGM
2023 年 10 月 16 日
n = 1:100;
x = ((-1).^(n+1))./(2*n-1);
sum(x)
1 件のコメント
SIBUNABIRWA
2023 年 11 月 30 日
編集済み: SIBUNABIRWA
2023 年 11 月 30 日
It is working out. Thank you very much
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!