MATLAB: How to use X&Y Arrays in a formula to get and Array answer

array

I have a formula L with variables X and Y. X and Y are arrays with eleven numbers in each. I want an array of 121 numbers (11*11) for my answer. But I am only getting eleven answers. (X1,Y1)(X2,Y2)(X3,Y3)……etc. What I want is: (X1,Y1)(X1,Y2)(X1,Y3)……
(X2,Y1)(X2,Y2)(X2,Y3)…..etc
Arrays:
x=[15:1:25];
y=[12:1:22];
Formula:
L= sqrt(((x-15).^2)+((y-25).^2))+sqrt(((x-10).^2)+((y-5).^2))+sqrt(((x-40).^2)+((y-10).^2))
Answer:
46.6822 46.2284 45.9273 45.8076 45.9019 46.2441 46.8645 47.7832 49.0065 50.5256 52.3212
How do I set up the arrays X and Y to give me an array answer??
Please help

Best Answer

Use ndgrid to generate the full array of combinations. You could also do it with implicit expansion, but that makes it harder to understand.