フィルターのクリア

For Loops with Increments Less Than One

2 ビュー (過去 30 日間)
cestcandice
cestcandice 2017 年 4 月 12 日
コメント済み: cestcandice 2017 年 4 月 12 日
I have to solve this equation with a for loop from 1 to 10 in increments of .01, but what I'm doing isn't working and I don't know why. It works just the way I want to when I take a way the constraint for the increment. Here's what I'm doing:
for t=1:.01:10
x(t)=a*cos((sqrt(g/l))*t)
end

採用された回答

Matt J
Matt J 2017 年 4 月 12 日
t=1:.01:10;
for i=1:length(t)
x(i)=a*cos((sqrt(g/l))*t(i))
end
  2 件のコメント
Matt J
Matt J 2017 年 4 月 12 日
Although, this entire loop could be done in one line,
x=a*cos((sqrt(g/l)) * (1:0.01:10) )
cestcandice
cestcandice 2017 年 4 月 12 日
Oh my gosh! Thank you... I have so much trouble with loops...
Yes, I know it can be done in one line. However, I have to use a for loop.
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by