Needing to increment a number within a sin function

I am creating a matrix which has a sin function in the diagonal. It starts with 10sin(0) and goes on to 10sin(1), 10 sin(2)... all the way to 10sin(19). How can I make this happen?

回答 (1 件)

Star Strider
Star Strider 2022 年 7 月 15 日

1 投票

Try something like this —
S = 10*sin(diag(0:19))
S = 20×20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8.4147 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9.0930 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.4112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -7.5680 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -9.5892 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.7942 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6.5699 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9.8936 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4.1212 0 0 0 0 0 0 0 0 0 0
See the documentation on diag for details.
.

2 件のコメント

John D'Errico
John D'Errico 2022 年 7 月 15 日
Would that be a "sin"ful answer? :)
Star Strider
Star Strider 2022 年 7 月 15 日
Quite definitely!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

質問済み:

2022 年 7 月 15 日

コメント済み:

2022 年 7 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by