getting error when using diag command

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 Comment

any one is having idea how to deal with this ?

Sign in to comment.

Answers (1)

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

no actually i want to use diag but its giving me error so i used blkdiag but its not giving me error but the matrix size is not proper using blkdiag
what should i change in the code to get proper size matrx?
From your question, you should use blkdiag. What is the expected size of Atila? From your question it should be 20x40
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.
Atilta size will depend on number of Nmode ...here i am using Nmod = 5

Sign in to comment.

Categories

Tags

Asked:

on 5 May 2013

Community Treasure Hunt

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

Start Hunting!