What does it mean to Initialize variables?

21 Ansichten (letzte 30 Tage)
and5314
and5314 am 1 Okt. 2015
Beantwortet: Walter Roberson am 1 Okt. 2015
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

Antworten (2)

Walter Roberson
Walter Roberson am 1 Okt. 2015
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 am 1 Okt. 2015
Initialised variables are the values of the variables at the beginning of the simulation, and the values of the constants in it.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by