フィルターのクリア

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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by