"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lncbd8$rii$1@newscl01ah.mathworks.com>...
>
> "Eric " <eric.malitz@gmail.com> wrote in message
> news:lnavdt$e9i$1@newscl01ah.mathworks.com...
> > Bear with me as I try to explain what I want. I doubt anyone here will be
> > able to walk me through this, but I've tried many different things and I'm
> > all out of options.
> >
> > In general, what I'm trying to get is a specific symmetric matrix where
> > the entries are functions I have, evaluated at a grid of points (using the
> > i and j corresponding to those grid points). What I first imagined doing
> > was to try to make a matrix of function handles. Can't do this. The matrix
> > I want is composed of (M2)x(M2) blocks of (N2)x(N2) entries. I have
> > functions A, B, D and E. They are functions of 2 variables i,j (these come
> > from the grid; the functions look like u(i+1,j)2*u(i,j)+... etc). I want
> > something resembling this:
> >
> > E(2,2) D(2,2) 0... B(2,2) A(2,2)
> > 0.... 0.....
> > D(2,3) E(2,3) D(2,3) 0... A(2,3) B(2,3) A(2,3)
> > 0..... 0.....
> > 0... D(2,4) E(2,4) D(2,4) 0.... A(2,4)
> > B(2,4) A(2,4) 0.....
> > 0 0 D(2,5) E(2,5)
> >
> >
> > And this continues on. The main diagonal of the whole MATRIX is a block
> > with E running down the main diagonal of this BLOCK but evaluated at
> > (2,2), (2,3), (2,4), etc..
> > The 2 off diagonals, next to E, are D, again evaluated at (2,2), (2,3),
> > etc. as you go down in rows. The blocks to the right and under this block
> > is the same idea but it's B along main diagonal and A on the 2 off
> > diagonals. These blocks all continue down in this symmetric fashion, and
> > the rest of is 0's. Again, (M2)x(M2) blocks of (N2)*(N2) entries. Let
> > me do a specific example where N=M=5:
> >
> > E D 0 B A 0 0 0 0 < evaluated at (2,2)
> > D E D A B A 0 0 0 <evaluated at (2,3)
> > 0 D E 0 A B 0 0 0 <evaluated at (2,4)
>
> This line is inconsistent with what you described above. The second 0 should
> be D(2, 4), shouldn't it? There are similar inconsistencies with other
> lines.
>
> > B A 0 E D 0 B A 0< evaluated at (3,2)
> > A B A D E D A B A<evaluated at (3,3)
> > 0 A B 0 D E 0 A B< evaluated at (3,4)
> > 0 0 0 B A 0 E D 0<evaluated at (4,2)
> > 0 0 0 A B A D E D<evaluated at (4,3)
> > 0 0 0 0 A B 0 D E< evaluated at (4,4)
> >
> > I challenge anyone to help me, after hours and hours of getting nowhere
> > with this.
>
> If your functions are vectorized (can be evaluated for vectors of values,
> not just scalars) then try the following:
>
> % Define some coordinates
> [c1, c2] = meshgrid(2:4);
>
> % Define a function
> E = @(x1, x2) x1+x2;
>
> % Evaluate E to get a vector of data
> v1 = E(c1(:), c2(:));
>
> % Use v1 to create a matrix with E on the main diagonal and one of the
> diagonals above the main.
> % Since the diagonal above the main is shorter, I needed to cut a few
> elements off the end of v1
> % to make the matrix returned by the second DIAG call the same size as the
> first
> M = diag(v1, 0)+diag(v1(1:end2), 2);
>
> What you should receive is a 9by9 M matrix whose main diagonal is [4 5 6 5
> 6 7 6 7 8] and where each of those diagonal elements is duplicated two
> elements to the right in their row.
>
> This generalizes to multiple functions (not just the one E that I used) and
> different diagonals.
>
> If the E, D, etc. return values are matrices instead of vectors the same
> size as the inputs, take a look at the BLKDIAG function, regular
> concatenation, or (depending on the specific pattern) the CIRCSHIFT function
> .
>
> E1 = [1 2;3 4];
> D1 = [5 6; 7 8];
> z = zeros(2);
> M2 = [E1 D1 z; D1 z E1; z E1 D1]
>
> 
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Thanks; Is there some version of blkdiag or something else which allows you to put blocks on the offdiagonals, instead of only main diagonal?
