# Multiple functions within a Module

I have a function that extracts a numerical value from two vectors, written as Spa[i_,j_]:=Flatten[LaU[i].LaD[j]][[1]]. (Note, I'm sure that this isn't the most efficient way to solve this problem but it works for my uses). In the next stage of my process, I'm having to calculate Spa functions when the argument needs something other than LaU, like something called QLaU[1], which is defined in a similar process (exact same dimensions etc).

Instead of manually creating a separate function like e.g SpaQ[i_,j_] :=Flatten[QLaU[1].LaD[2]][[1]], I'm hoping to use a Module function to simply combine the two together, and have MMA recognise the type of function. Is this possible within the scope of Module? I'm essentially trying to put a couple of functions within the single overall Spa function, to keep the final results looking similar.

• Spa[lau_,i_,j_]:=Flatten[lau[i].LaD[j]][[1]]? – Alan Jan 31 '19 at 18:24
• May I ask how that works? Spa with three arguments means I need to specify three bits of information, and I'm not sure how that would work for both LaU and QLaU? – Brad Jan 31 '19 at 18:26
• Pass the symbol name LaU or QLaU as an argument to Spa. That is what Alan is implying in his comment. – Shredderroy Jan 31 '19 at 19:05

## 1 Answer

If you want to constrain Spa to only accept LaU and LaD, whichis good practice, you can define it like this:

Spa[la:(LaU | LaD), i_, j_] := Flatten[la[i].LaU[j]][[1]]