Register to reply 
Block diagonal matrices in MATLAB? 
Share this thread: 
#19
Oct2110, 05:08 PM

P: 124

A=k*ones(n,n) kron(eye(M),A) 


#20
Oct2210, 08:43 AM

P: 341

rax,it is the same as the block diagonal. So for your last example,
B = 0.5*eye(4) + 0.25*(kron([0 1;1 0],ones(2)) will do. Basically it is the application of the same idea, you build from the smallest structure to the bigger one. Of course, there are shorter ways to do it. But it would be an overkill for these sizes. 


#21
Oct2210, 09:49 AM

P: 32

Thanks very much for this, both of you  it's really helpful in terms of understanding how Matlab works. Don't know how you figured it out yourself! Cheers, Rax 


#22
Oct2410, 04:36 AM

P: 341

Yes, I guess it would change the approach but I don't think that it would be something that slight modifications can not fix. When you are done, give us the actual 1001000 matrix structure and we can figure it out together. (I am not sure what you want on the sup and super diagonals)



#23
Oct2410, 11:23 AM

P: 124




#24
Oct3010, 01:19 PM

P: 32

So the code is running alright for the time being, but apparently draws on too much memory for > 2000 x 2000 (ish).
I'm working on an inbetween step now, not requires me to call on this code, run it for several values of one of the variables, generate a graph with title, axes, grid etc and save it to a specific file. I've figured out how to do everything except the last step (viz. saving the generated figure to a *specific* file that is not simply the matlab directory). Would I simply include a change director "cd  " command *in* the .m file to do this? Also, is there a more efficient way of creating a vector of the outputs of my function than running a for loop? i.e. is it possible to write a .m file that takes a range of values, with a specified increment and will calculate the output for each of those values *without* using a for loop? Again (&again!) thanks for the help. I've spent so much time searching around on line to no avail. Cheers, Rax 


#25
Oct3110, 06:20 PM

P: 341

Well if you are not doing complicated stuff, then, you can vectorize your variables, and send it to your function as vectors instead of computing one by one. it really depends on what you are trying to do.



#26
Nov311, 09:54 AM

P: 3

Hello,
I have similar question, but with additional problem. I will appreciate if somebody can help me. I want to creat block diagonal matrix (blocks 3x3, different), but the data for it saved as a 4D vector: data = data(1:N,1:M,1:3,1:3) I want to create main diagonal from data(2,1:M,1:3,1:3). I mean M1 = data(2,1,1:3,1:3), M2 = data(2,2,1:3,1:3) and so on... Thank you in advance. 


#27
Nov811, 04:56 AM

P: 3

I found some solution to my problem (may be it isn't the best one, but improves the run time more than in 10 compare to using "for").
1. Created 5 vectors of main diagonals using coordinates with 3 step jump in new vectors. I'll better put part of my code here (vector creation) 2. Made "sparse" on all the vectors in order to improve calculation time in the future. 3. Created diagonal matrix using function "diag". 


#28
Dec2911, 05:07 AM

P: 2

Dear friends
I have a same problem. I try to create a block tridiagonal matrix in matlab and I tried everything but it is not working for me. I have matrices A, B, C of dimension 4*4. these matrices are dependent on (n) and in each n has different values. I have to develop a block tridiagonal matrix D whose leading diagonal is matrix A and whose upper diagonal is matrix B and lower diagonal is Matrix C( as mentioned because these matrices are dependent to n they will be different when the row of main matrix (D) changed). I will be grateful if anyone can help me how to write it in matlab and especially as a part of Mfile. 


#29
Oct2912, 09:41 AM

P: 1

Hi,
I have a similar problem. I want to create a block diagonal matrix with diagonals B1,B2,..Bn but each Bi has different size. Could anyone suggest a method to create this matrix quickly? Thank you in advance! Best, Ultione 


Register to reply 
Related Discussions  
Need help: Proof Nullrank theorem with block matrices  Linear & Abstract Algebra  0  
Matrices in matlab  Math & Science Software  2  
The integration block in matlab  Math & Science Software  3  
Matrices in Matlab  Math & Science Software  5  
A.B= m1, B.A=m2, m1 and m2 diagonal matrices  Linear & Abstract Algebra  9 