下标索引必须是实数正整数或逻辑错误 [英] Subscript indices must either be real positive integers or logical error

查看:92
本文介绍了下标索引必须是实数正整数或逻辑错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Q2. (30分)位置d是沿直线运动的物体的时间(t)的函数,其公式为:

Q2. (30 points) The position d as a function of time (t) of a body that moves along a straight line is given by:

            d(t)= ‒ 0.2t4+0.5t3+15t-80 meters

粒子的速度v(t)由d(t)相对于t的导数确定,加速度a(t)由v(t)相对于t的导数确定. 通过使用现有的数学知识,推导粒子的速度和加速度的表达式,并绘制位置,速度和加速度随时间变化的图,其中时间为0≤t≤10 s,增量为0.1 s,类似于以下屏幕截图.使用subplot命令可在同一页面上绘制三个图,其中位置图在顶部,速度在中间,加速度在底部.用正确的单位适当地标记轴.

The velocity v(t) of the particle is determined by the derivative of d(t) with respect to t, and the acceleration a(t) is determined by the derivative of v(t) with respect to t. Derive the expressions for the velocity and acceleration of the particle by using your existing math knowledge, and make plots of the position, velocity, and the acceleration as a function of time for 0 ≤ t ≤ 10 s with 0.1 s increments similar to following screenshot. Use the subplot command to make the three plots on the same page with the plot of position on the top, the velocity in the middle, and the acceleration at the bottom. Label the axes appropriately with the correct units.

您能帮我解决这个问题吗?

Could you help me for this question?

我写道:

 t=1:0.1:10

然后:

 d(t)=-0.2*t.^4+0.5*t.^3+15*t-80

但是我说:

下标索引必须是实数或逻辑.

Subscript indices must either be real positive integers or logicals.

这是什么意思?

推荐答案

如错误所示,t必须为整数或逻辑.

As the error says, t needs to be an integer or logical.

但是您的t是t=1:0.1:10,因此是一个十进制值.

But your t is t=1:0.1:10, therefore a decimal value.

您可以直接写(请注意,.*也是必要的)

you can just write (be aware that also .* is necessary)

d = -0.2.*t.^4+0.5.*t.^3+15.*t-80

,您将获得与时间向量t相匹配的位移向量d.

and you will get a proper displacement vector d to your time vector t.

原因是您要为d分配值,这需要索引,索引是实数正整数. 因此,尽管不是必须的,您可以创建一个索引向量:

The reason is that you want to assign values to d, which requires indices, which are real positive integers. So you could, though not necessary, create an index vector:

idx_t = 1:numel(t); 

并分配d,如:

d(idx_t) = -0.2.*t.^4+0.5.*t.^3+15.*t-80

第二种情况,当索引向量是逻辑时,它就像掩码一样工作.

The second case, when the index vector is logical, it works like a mask.

例如

mask = logical( [1 0 1 0 1 0 1 0 1 0] );
t_new = t(mask);

将删除向量t的每第二个值.

would delete every second value of your vector t.

这篇关于下标索引必须是实数正整数或逻辑错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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