Index exceeds the number of array elements (1).
1 次查看(过去 30 天)
显示 更早的评论
i keep getting this error from my code:
FuerzaMotor = 7475 %Dame la fuerza del motor
AceleracionInicial = 5 %Dame la aceleración inicial
CoeficienteResistencia = 0.183 %Dame la constante de fricción de aire
MasaVehiculo = 1495 %Dame la masa del vehículo
Delta = 0.01;
%Inicialización de vectores
vt = [0:Delta:10];
va= [0:Delta:10];
vdx= [0:Delta:10];
vdy= [0:Delta:10];
vv= [0:Delta:10];
vFM=[ 0:Delta:10];
vFR= [0:Delta:10];
%Damos los valores iniciales a la primera posición del vector
vv(1) = 0;
va(1) = AceleracionInicial;
vdx(1) = 0;
vdy(1) = 0;
vFR(1)= 0;
VFM(1)= FuerzaMotor;
angulo= 15;
for i = 2:1001
vv(i)= vv(i-1) + va(i-1)*Delta;
vFR(i)= CoeficienteResistencia*vv(i)^2;
va(i)=(FuerzaMotor - vFR(i))/MasaVehiculo;
angulo(i)= angulo(i) - 3*Delta
vFR(i)= FuerzaMotor;
vdx(i)= vdx(i-1) + vv(i-1)*cosd(angulo)*Delta;
vdy(i)= vdy(i-1) + vv(i-1)*sind(angulo)*Delta;
end
figure ("Name","X contra Y");
plot(vdx,vdy);
1 个评论
Stephen23
2020-10-22
The square brackets are completely superfluous (you are not concatenating anything), get rid of them.
The only purpose they serve is to mislead beginners into thinking they are creating a "list" (which they are not).
采纳的回答
Stephen23
2020-10-22
编辑:Stephen23
2020-10-22
Your define angulo as a scalar (i.e. size 1x1):
angulo= 15;
and then a few lines later with i=2 you try to access its 2nd element (which does not exist):
angulo(i)= angulo(i) - 3*Delta
whic of course throws an error. Possibly what you want is this:
angulo = angulo - 3*Delta;
0 个评论
更多回答(1 个)
Ameer Hamza
2020-10-22
There are issues with your indexing. Try the following code, and check its difference with your code
for i = 2:1001
vv(i)= vv(i-1) + va(i-1)*Delta;
vFR(i)= CoeficienteResistencia*vv(i)^2;
va(i)=(FuerzaMotor - vFR(i))/MasaVehiculo;
angulo(i)= angulo(i-1) - 3*Delta;
vFR(i)= FuerzaMotor;
vdx(i)= vdx(i-1) + vv(i-1)*cosd(angulo(i))*Delta;
vdy(i)= vdy(i-1) + vv(i-1)*sind(angulo(i))*Delta;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!