getting error when using diag command

8 views (last 30 days)
Aniket
Aniket on 5 May 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);

Answers (1)

Walter Roberson
Walter Roberson on 5 May 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 Comments
Aniket
Aniket on 5 May 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 on 5 May 2013
Atilta size will depend on number of Nmode ...here i am using Nmod = 5

Sign in to comment.

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!