Sorry, I had the impression that the question was where to write the function, based on the title, "where to write function".
If the question is how to plot real(Hy) vs x/a, then you're going to have to get Hy out of that function or plot from inside the function (both of which would require calling the function at some point). But also, there is an undefined variable be you'd have to define first. I'll just pick be = 1 to show how it might work:
bsinf = sqrt(ef*es/(ef+es));
x = linspace(-3,3,601)*a;
Hy = pwga(la0,ef,ec,es,pc,ps,a,bsinf,m,tol,x);
plot(x/a, real(Hy), 'linewidth',2);
function Hy = pwga(la0,ef,ec,es,pc,ps,a,bsinf,m,tol,x)
psi = atanh(-pc*ac/ga)/2- atanh(-ps*as/ga)/2;
Hy = cosh(ga*a - psi).*exp(as*(x+a)).*(x<-a) + ...
cosh(ga*a + psi).*exp(-ac*(x-a)).*(x>a) + ...
cosh(ga*x + psi).*(abs(x)<=a);
In this case the input argument names in the definition of the function are the same as the names of the variables the function is called with, but this need not be the case, and it's important to understand that if you want to understand how functions work. For example, you can try the following to see how it works:
add_two_numbers(first_a,first_b)
add_two_numbers(second_a,second_b)
function c = add_two_numbers(a,b)