在给定代码的上下文中,此语法[0:1:5]是什么意思? [英] What does this syntax [0:1:5] mean (do) in the context of the given code?
问题描述
我不明白下面的代码中如何使用[0:1:5]
:
I don't understand how [0:1:5]
is being used in the code below:
function [x , y] = plotTrajectory(Vo,O,t,g)
% calculating x and y values
x = Vo * cos(O) * t ;
y = Vo*(sin(O)*t)-(0.5*g*(t.^2));
plot (x,y);
hold on
end
for i = (0: (pi/8): pi);
[x,y] = plotTrajectory(10,i,[0:1:5],9.8);
end
推荐答案
每个参数都用于查找特定的X
和Y
值. O
以pi/8
的步长从0变为pi
,而Vo
,t
和g
保持不变.
Each of the parameters are being used to find particular X
and Y
values. O
changes from 0 to pi
in steps of pi/8
while Vo
, t
and g
remain unchanged.
t
变量只是一个从0到5的数组,以1为步长,因此总共定义了6个时间点.通过这些时间点和特定的O
值,但在整个工作过程中Vo
,t
和g
的值保持恒定,定义了6个X
和Y
点,并且因此,将它们绘制在图形上.为每个O
值生成一个图形,因此生成了6个不同的X
和Y
点的集合.每个值为O
的图形都绘制在同一图形上.
The t
variable is simply an array from 0 to 5 in steps of 1 and so there are 6 time points defined all together. With these time points and with a particular value of O
, but with the values of Vo
, t
and g
being held constant throughout this entire endeavour, 6 X
and Y
points are defined and are thus plotted on a graph. A graph is generated for each value of O
and thus a set of 6 different X
and Y
points are generated. Each graph with each value of O
are all plotted on the same graph.
我们可以用伪代码重写上面的代码,以使其更容易理解,如下所示:
We can rewrite the above code in pseudo-code to make it easier to understand as follows:
for i = 0, pi/8, 2*pi/8, ..., pi
define Vo = 10
define O = i
define t = [0, 1, 2, 3, 4, 5]
define g = 9.8
run function plotTrajectory(Vo, O, t, g)
end
function plotTrajectory(Vo, O, t, g)
calculate x = Vo * cos(O) * t, for t = 0, 1, 2, 3, 4, 5
calculate y = Vo * (sin(O) * t) - (0.5 * g * t^2), for t = 0, 1, 2, 3, 4, 5
plot x and y for t = 0, 1, 2, 3, 4, 5 on the same graph
end
这篇关于在给定代码的上下文中,此语法[0:1:5]是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!