Suppose I have a matrix
mat[a_,b_,c_,w0_,y0_][omega_,ak_]:={
{I TMM[a,b,c][omega,ak]w0, -I TMP[a,b,c][omega,ak]},
{TMP[a,b,c]y0, I TMM[a,b,c]w0 y0}}
Now the problem is that I have two sets of definitions for the functions TMM
and TMP
, which I will use the letter g
and m
to distinguish:
gTMM[a_,b_,c_][omega_,ak_]:=a*b*c
gTMP[a_,b_,c_][omega_,ak_]:=a*b*c*omega*ak
mTMM[a_,b_,c_][omega_,ak_]:=a*b*c^2
mTMP[a_,b_,c_][omega_,ak_]:=a*b*c^2*omega*ak
The above are just examples. In the actual codes they are a lot more complicated. So far my approach is to define two matrices gmat
and mmat
to take into account the two sets of TMM
and TMP
. Both matrices have exactly the same structure, the only difference is that one uses mTMM/mTMP
and the other one uses gTMM/gTMP
. This works, but as I extend my codes, it is becoming more and more troublesome (especially when the size of the matrix is something like 10x10 but not 2x2). So I try to use a single mat
to represent the two cases, and define another variable type
and do some something like:
(* definitions of gTMM, gTMP, mTMM, mTMP which are not shown here *)
mat[type_:"M", a_,b_,c_,w0_,y0_][omega_,ak_]:=Module[{TMM,TMP},
If[type=="G", TMM=gTMM;TMP=gTMP, TMM=mTMM;TMP=mTMP];{
{I TMM[a,b,c][omega,ak]w0, -I TMP[a,b,c][omega,ak]},
{TMP[a,b,c]y0, I TMM[a,b,c]w0 y0}}
But it is not working. How to make it work so that I can switch between the two definitions of TMM
and TMP
inside one single mat
?