What does it mean to Initialize variables?

19 ビュー (過去 30 日間)
and5314
and5314 2015 年 10 月 1 日
回答済み: Walter Roberson 2015 年 10 月 1 日
If a stationary ball is released at a height h_0 above the surface of the Earth with a vertical velocity〖 v〗_0, the position and velocity of the ball as a function of time will be given by the equations:
h(t)= 1/2 gt^2 + v_0 t + h_0
v(t)= gt + v_0
where g is the acceleration due to gravity (-9.81 m/s^2), h is the height above the surface of the Earth (assuming no air friction), and v is the vertical component of velocity. Create variables for this problem
Initialize g, v_0= 1 m/s , and h_0=2 m
Initialize t to 1 second

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 1 日
Initialize means to assign them a value for the first time. You might change their values afterwards or you might not.
For example,
total = x;
if y > 5
total = total + y;
end
Here we could only have added y to total once we had already assigned a value to total. If the code had instead been
if y > 5
total = total + y;
end
then it would have failed because total did not exist yet.

Star Strider
Star Strider 2015 年 10 月 1 日
Initialised variables are the values of the variables at the beginning of the simulation, and the values of the constants in it.

カテゴリ

Help Center および File ExchangeGeometric Geodesy についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by