在给定代码的上下文中,此语法[0:1:5]是什么意思? [英] What does this syntax [0:1:5] mean (do) in the context of the given code?

查看:82
本文介绍了在给定代码的上下文中,此语法[0:1:5]是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白下面的代码中如何使用[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

推荐答案

每个参数都用于查找特定的XY值. Opi/8的步长从0变为pi,而Votg保持不变.

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值,但在整个工作过程中Votg的值保持恒定,定义了6个XY点,并且因此,将它们绘制在图形上.为每个O值生成一个图形,因此生成了6个不同的XY点的集合.每个值为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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆