why do I get --- ??? Subscript indices must either be real positive integers or logicals.----- on my code

3 次查看(过去 30 天)
this is my code:
% code
e
clc;
m=1;
c=0;
k=10;
wn=sqrt(k/m);
xi=c/(2*sqrt(k*m));
t0=0;
tf=5;
muestras=1000;
for i=1:muestras+1
t(i)=t0+(i-1)*(tf-t0)/muestras;
if t(i)<=tf
x(i)=1/m((t(i)*cos(t(i)))*(((exp(-wn*t(i)))*(sin(t(i))-wn*cos(t(i)))+wn)/wn^2+1)+t(i)*(sin(t(i)))*(((-exp(-wn*t(i)))*(wn*(sin(t(i)))+(cos(t(i)))/wn^2+1)+(1/(wn^2+1))))-(1/(wn^2+1)^3)*((-exp(-wn*t(i))*-(wn^5)*(t(i)^2)+2*(wn^4)*t(i)^1+2*(wn^3)*(t(i)^2+1)+wn*(t(i)^2-6)-(2*wn^3-6*wn)*(cos(t(i))))));
end
end
plot(t,x,'r')
xlabel('t')
ylabel('x(t)')
grid
hold on
the display shows the next error: ----??? Subscript indices must either be real positive integers or logicals.
Error in ==> EXACTOprueba at 15 x(i)=1/m((t(i)*cos(t(i)))*(((exp(-wn*t(i)))*(sin(t(i))-wn*cos(t(i)))+wn)/wn^2+1)+t(i)*(sin(t(i)))*(((-exp(-wn*t(i)))*(wn*(sin(t(i)))+(cos(t(i)))/wn^2+1)+(1/(wn^2+1))))-(1/(wn^2+1)^3)*((-exp(-wn*t >>

回答(1 个)

KSSV
KSSV 2017-10-31
编辑:KSSV 2017-10-31
% code
e
clc;
m=1;
c=0;
k=10;
wn=sqrt(k/m);
xi=c/(2*sqrt(k*m));
t0=0;
tf=5;
muestras=1000;
t = zeros(muestras+1,1) ;
for i=1:muestras+1
t(i)=t0+(i-1)*(tf-t0)/muestras;
if t(i)<=tf
x(i)=1/m*((t(i)*cos(t(i)))*(((exp(-wn*t(i)))*(sin(t(i))-wn*cos(t(i)))+wn)/wn^2+1)+t(i)*(sin(t(i)))*(((-exp(-wn*t(i)))*(wn*(sin(t(i)))+(cos(t(i)))/wn^2+1)+(1/(wn^2+1))))-(1/(wn^2+1)^3)*((-exp(-wn*t(i))*-(wn^5)*(t(i)^2)+2*(wn^4)*t(i)^1+2*(wn^3)*(t(i)^2+1)+wn*(t(i)^2-6)-(2*wn^3-6*wn)*(cos(t(i))))));
end
end
plot(t,x,'r')
xlabel('t')
ylabel('x(t)')
grid
hold on
There is problem in the line NO: 15....you wrote 1/m()..it should be 1/m*()

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by