Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I make an array with a function that defines every element?

1 回表示 (過去 30 日間)
Lisanne Hogeveen
Lisanne Hogeveen 2016 年 10 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I would like to make an array theta_i=(theta_1, theta_2, .., theta_n) such that I can define a function theta_j=1/j for all j. So the result would be: theta_i=(1, 1/2, 1/3, ..., 1/n) for some n.

回答 (2 件)

Adam
Adam 2016 年 10 月 5 日
You don't need a function, just
1 ./ theta_i
will do
  1 件のコメント
Jan
Jan 2016 年 10 月 5 日
Or to be exact:
theta = 1 ./ (1:n)

Pritesh Shah
Pritesh Shah 2016 年 10 月 5 日
for i=1:lenth(theta_i)
y(i)=1/i;
end

Community Treasure Hunt

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

Start Hunting!

Translated by