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

1 Ansicht (letzte 30 Tage)
pankaj khaire
pankaj khaire am 8 Aug. 2021
Kommentiert: Walter Roberson am 9 Aug. 2021
'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);

Antworten (1)

DGM
DGM am 9 Aug. 2021
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 Kommentar
Walter Roberson
Walter Roberson am 9 Aug. 2021
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++)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by