I want to multiply every element of a 782x782 matrix with a function that depends on the two indexes of that element, I tried MapIndexed, but I don't seem to fully understand how it works.

The function is :

f[x_, y_] := Exp[I*(2 Pi/\[Lambda]g)*zi*Sqrt[1 - (\[Lambda]g*x/(2*a*dx))^2 + (\[Lambda]g*y/(2*b*dx))^2]]

where x and y, are the indexes of the elements, and everything else already defined constants.

That function is independent of the actual value of the matrix, I just care about how to transmit the index information.

I thought about using MapIndexed to give it the index information, but I don't seem to fully grasp how to do that. Is there another easier way, or just a correct way of doing this that you can think of?

Thanks in advance.

Edit : Sorry, 782x782, but I'm guessing your answers can be used just changing the 2x2.

  • $\begingroup$ Letting mat be the original matrix, try mat Array[f, {2, 2}]. $\endgroup$ – J. M. will be back soon Mar 9 '18 at 12:51
A  = Array[a, {2, 3}]
matf = Table[f[x, y], {x, 1, 2}, {y, 1, 3}]
matf A  (* elementwise multiplication *)

I tried MapIndexed, but ...

Using @Ulrich's example A = Array[a, {2, 3}]

MapIndexed[# f @@ #2 &, A, {2}]

{{a[1, 1] f[1, 1], a[1, 2] f[1, 2], a[1, 3] f[1, 3]},
{a[2, 1] f[2, 1], a[2, 2] f[2, 2], a[2, 3] f[2, 3]}}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.