I have a $n \times k$ Matrix of data that I want to feed into an equation and solve for an unknown variable. I suppose I can always just convert the Matrix into a long Array but I'd like to learn how to do this while keeping the data structure as is.
I want to be able to solve $n \times k$ FindRoots in one shot and mimicking some code from MMA.SE this is what I have managed.
f = x^(Mod[a, 3]) + b
a = {{2, 5, 8}, {1, 4, 7}};
b = {{-3, -5, -7}, {3, 5, 7}};
eqn = Table[(#[[j]] == 0), {j, 1, Dimensions[f][[2]]}] & /@ (f)
{{-3 + x^2 == 0, -5 + x^2 == 0, -7 + x^2 == 0}, {3 + x == 0, 5 + x == 0, 7 + x == 0}}
Table[FindRoot[#[[i]], {x, 1}] & /@ eqn, {i, 1, Dimensions[f][[2]]}]
{{{x -> 1.73205}, {x -> -3.}}, {{x -> 2.23607}, {x -> -5.}}, {{x -> 2.64575}, {x ->7.}}}
As you can see, this works but is a kind of a mess. I am hoping I can be helped in the direction of a cleaner, better code and learn how to use pure functions on n-dimensional lists. Thanks.
fshould be afteraandb, no? – J. M.♦ Oct 3 '12 at 1:56