필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Mariela Flores
Mariela Flores 2017년 10월 31일
편집: KSSV 2017년 10월 31일
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