I have a program that currently uses a for loop to iterate through a set of functions. I've tried using parfor but that only works on the university's version of Matlab. I'd like to vectorize the handling of this so that a for loop isn't necessary. The equations I'm using basically call different types of Bessel functions and are contained in separate functions.
Here's what I'm trying to do: For each value of m, build a vector of matrix elements for each required matrix. Then build each full matrix. I think this is working correctly.
Where it's throwing an error is on the final matrix multiplication... even if I just multiply the left 2x2 by the middle 2x2 I get the dreaded error:
??? Error using ==> mtimes Inner matrix dimensions must agree. Error in ==> @(m)CL(m)*CM(m)*CR(m)
% Vector for summation. 1 row, 301 columns with data from 0->300
m_max=301;
m=[0:m_max-1];
% Build the 300 elements for the left 2x2 matrix.
CL_11=@(m) H1(m,alpha1);
CL_12=@(m) H2(m,alpha1);
CL_21=@(m) n1*dH1(m,alpha1);
CL_22=@(m) n1*dH2(m,alpha1);
% Build the 300 elements for the middle 2x2 matrix.
CM_11=@(m) n1*dH2(m,alpha2);
CM_12=@(m) -1*H2(m,alpha2);
CM_21=@(m) -1*n1*dH1(m,alpha2);
CM_22=@(m) H1(m,alpha2);
% Build the 300 elements for the right 2x1 matrix.
CR_11=@(m) J(m,alpha3);
CR_21=@(m) n2*dJ(m,alpha3);
% Build the left (CL), middle (CM) and right (CR) matrices.
CL=@(m) [CL_11(m) CL_12(m);CL_21(m) CL_22(m)];
CM=@(m) [CM_11(m) CM_12(m);CM_21(m) CM_22(m)];
CR=@(m) [CR_11(m);CR_21(m)];
% Build the vector containing the products of each triplet of
% matrices.
C=@(m) CL(m)*CM(m)*CR(m);
cl=CL(m)
cm=CM(m)
cr=CR(m)
c=CL(m)*CM(m)*CR(m)
If you have any suggestions or recommendations, I'd greatly appreciate it! I'm still a newbie with Matlab and am trying to develop a higher level of ability with use of matrices and vectors.
Thanks!!