3 errors in a script line - 11, 13, 28

2 次查看(过去 30 天)
'Shock Response Spectrum';
'CrLf';
ymax=[ ];
ff=[ ];
fmin=1;
fmax=1000;
n=90;
qv=(fmax/fmin)^(1/n);
T=1/get(input1,'freq');
Q=10;
for[i=0;1;1i<n;i=i+1];
{
fn=[fmin*qv^i];
ff=[ff,fn];
wn=2*pi*fn;
A=wn*T/2/Q;
B=wn*T*sqr(1-1/4/Q/Q);
b0=1-exp(-A)*sin(B)/B;
b1=2*exp(-A)*(sin(B)/B-cos(B));
b2=exp((-2)*A)-exp(-A)*sin(B)/B;
a1=(-2)*exp((-1)*A)*cos(B);
a2=exp((-2)*A);
BB=[b0,b1,b2];
AA=[-a1,-a2];
y=filter(input1,BB,AA);
yy=max(y);
ymax=[ymax,yy];
};
save(ff);
save(ymax);

回答(1 个)

DGM
DGM 2021-8-9
T=1/get(input1,'freq');
input1 is a missing variable/object, so you'll have to figure that out. If this is is someone else's code, I have less information than you do about what it could possibly be.
for[i=0;1;1i<n;i=i+1];
{
% ...
};
I have no idea what language this is from, but it's not MATLAB. I am not familiar with any 4-argument for loop syntax, so I have no idea what the 1 means. You're using i as both an integer index and you're attempting to explicitly use it as a complex number. Both i and j are sqrt(-1). Unless you're using them as that, don't cause problems by overloading them for use as indices or something.
B=wn*T*sqr(1-1/4/Q/Q);
I'm assuming that's supposed to be sqrt()?
y=filter(input1,BB,AA);
Again, I'm assuming input1 is some variable you have already.
Without the missing variable, this is my best guess:
clc; clearvars
ymax=[ ];
ff=[ ];
fmin=1;
fmax=1000;
n=90;
qv=(fmax/fmin)^(1/n);
%T=1/get(input1,'freq');
T = 1/200; % fake number to make it run
Q=10;
for k = 0:n-1 % is this right?
fn=fmin*qv^k;
ff=[ff,fn];
wn=2*pi*fn;
A=wn*T/2/Q;
B=wn*T*sqrt(1-1/4/Q/Q);
b0=1-exp(-A)*sin(B)/B;
b1=2*exp(-A)*(sin(B)/B-cos(B));
b2=exp((-2)*A)-exp(-A)*sin(B)/B;
a1=(-2)*exp((-1)*A)*cos(B);
a2=exp((-2)*A);
BB=[b0,b1,b2];
AA=[-a1,-a2];
%y=filter(input1,BB,AA);
y=filter(BB,BB,AA); % just cram something in it so it runs
yy=max(y);
ymax=[ymax,yy];
end
  1 个评论
Walter Roberson
Walter Roberson 2021-8-9
I am wondering if
for[i=0;1;1i<n;i=i+1];
is some kind of combination of
for i=0:1:1
and a C / C++
for (i=0; i <n; i++)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by