getting error when using diag command

2 Ansichten (letzte 30 Tage)
Aniket
Aniket am 5 Mai 2013
hello i am doing simulation related to duct to control noise and i have structure of matrices, for example i am creating Anr matrices the An and then i want to create Atilta which contains all these matrices according formulas but when i am using diag it gaves me error related to scalar what should i do ?
the formulas are following
*********************
Nmod = 5; % modes in duct 1 to 5
L = 1.2; % length of duct
K = 0.051; % impedance at one end
zi = 0.315;
zm = 0.775;
c = 340 ;
roh = 1.225;
S = 1;
eta =1 ;
betan = -(1:Nmod)*pi/L;
alfa = 1/(2*L)*log((1-K)/(1+K));
Atilta = []; % final matrices
for i = 1:Nmod
%
Anr = c * [alfa betan; -betan alfa]; % formula for Anr matrices
%
Ani = c*eta*[1 0;0 1];
%
An = [Anr -Ani ; Ani Anr]; % Anr and Ani matrices pack in An
Atilta = diag(Atilta,An);
end
***************
from this i want to create state space matrices
and my Atilta matrix will be like this
but when i am using diag command it will give me error as following
Error using diag
K-th diagonal input must be an integer scalar.
Error in modeNmatrices (line 41)
Atilta = diag(Atilta,An);
  1 Kommentar
Aniket
Aniket am 5 Mai 2013
any one is having idea how to deal with this ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 5 Mai 2013
When you use the two-argument form of diag(), the second argument needs to be the number of the diagonal. You cannot use diag() to directly modify an existing array.
I am confused: your error message uses diag() but your code uses blkdiag() which can take an array as its second argument.
  4 Kommentare
Aniket
Aniket am 5 Mai 2013
yes from my question it is coming 20*40 ,in paper they haven't specified matrix size they just give a matrix structure , its look like in the above diagram
the paper name is
Active Noise Reduction in Ducts of Actuating Dynamics Using Two Periodic Control Signals.
Aniket
Aniket am 5 Mai 2013
Atilta size will depend on number of Nmode ...here i am using Nmod = 5

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear Algebra finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by