# How to output results in a specific format？

i get some results using Table,codes are as this

nu = 8.163265306122447;
Table[FindRoot[(I*m[k])*Tanh[I*m[k]] - nu, {m[k], k*\[Pi],
k*\[Pi] - \[Pi]/2, k*\[Pi] + \[Pi]/2}], {k, 1, 10}]


and it outputs

{{m[1] -> 1.78621}, {m[2] -> 5.28713}, {m[3] -> 8.66944}, {m[4] ->
11.9678}, {m[5] -> 15.2155}, {m[6] -> 18.4326}, {m[7] ->
21.6303}, {m[8] -> 24.8149}, {m[9] -> 27.9906}, {m[10] -> 31.1597}}


i just wan to output the results in this form and in one cell

m[1]=1.78621;
m[2]=5.28713;
m[3]=8.66944;
...


so how to deal with it? iam sorry i have no trying codes as i don't konw how to try.

nu = 8.163265306122447;
s1 = Table[
FindRoot[(I*m[k])*Tanh[I*m[k]] - nu, {m[k], k*\[Pi],
k*\[Pi] - \[Pi]/2, k*\[Pi] + \[Pi]/2}], {k, 1, 10}]

s2 = s1 /. {"->" -> "="}


however it doesn't work

• You're on the wrong way. Please press F1 and read the document of ReplaceAll (/.) carefully. ReplaceAll is a function you can't circumvent as long as you're using Mathematica. – xzczd Nov 6 '19 at 13:33
• i don't konw how to repalceall about the [,-> and some specific characters – dcydhb Nov 6 '19 at 13:48
• Now read the document of Rule and Equal, and read this Chinese tutorial: note.youdao.com/ynoteshare1/… especially the 函数和它的马甲 section. – xzczd Nov 6 '19 at 13:50
• nu = 8.163265306122447; Table[FindRoot[(I*m[k])*Tanh[I*m[k]] - nu, {m[k], k*\[Pi], k*\[Pi] - \[Pi]/2, k*\[Pi] + \[Pi]/2}][[1]], {k, 1, 10}] /. Rule :> Equal // Column – Bob Hanlon Nov 6 '19 at 14:05
• @Bob Hanlon,it seems that i want to use =and delete [ and ] – dcydhb Nov 6 '19 at 14:14

The code depends on what are you going to achieve. If your aim is simply to assign the values to m[i] the most straightforward way is the following. Let res be your result:

res = {{m[1] -> 1.78621}, {m[2] -> 5.28713}, {m[3] ->
8.66944}, {m[4] -> 11.9678}, {m[5] -> 15.2155}, {m[6] ->
18.4326}, {m[7] -> 21.6303}, {m[8] -> 24.8149}, {m[9] ->
27.9906}, {m[10] -> 31.1597}};


Let us first remove the internal curly braces:

res1 = Flatten[res, 1]

(*  {m[1] -> 1.78621, m[2] -> 5.28713, m[3] -> 8.66944, m[4] -> 11.9678,
m[5] -> 15.2155, m[6] -> 18.4326, m[7] -> 21.6303, m[8] -> 24.8149,
m[9] -> 27.9906, m[10] -> 31.1597}  *)


And now you easily get the value of any of your m-s. Say, for m[5] you should only evaluate

m[5] /. res1

(* 15.2155 *)


This construct you can substitute in any your code, where you need to substitute m[i].

You can also assign the values for all m[i] once forever:

MapAt[(Apply[Set, #] &), res1, All]

(*  {1.78621, 5.28713, 8.66944, 11.9678, 15.2155, 18.4326, 21.6303, \
24.8149, 27.9906, 31.1597}   *)


Now, let us check, say, the value of m[2]:

m[2]

(*  5.28713  *)


Finally, may it by that you only wish to represent them in a form that is convenient for a visual inspection? In that case do the following:

Column[MapAt[(Apply[Equal, #] &), res1, All]]


Have fun!

• it seems that i can't use your code,res = {{m[1] -> 1.78621}, {m[2] -> 5.28713}, {m[3] -> 8.66944}, {m[4] -> 11.9678}, {m[5] -> 15.2155}, {m[6] -> 18.4326}, {m[7] -> 21.6303}, {m[8] -> 24.8149}, {m[9] -> 27.9906}, {m[10] -> 31.1597}}; res1 = Flatten[res, 1] Column[MapAt[(Apply[Equal, #] &), res1, All]] and it runs out MapAt::psl: Position specification All in MapAt[Equal@@#1&,{m[1]->1.78621,m[2]->5.28713,m[3]->8.66944,m[4]->11.9678,m[5]->15.2155,m[6]->18.4326,m[7]->21.6303,m[8]->24.8149,m[9]->27.9906,m[10]->31.1597},All] is not an integer or a list of integers. >> – dcydhb Nov 7 '19 at 2:05
• and the most important is that when i cpoy this result cell to MS word or txt or matlab`,the form changed and you can't use it. – dcydhb Nov 7 '19 at 2:07
• That was my question from the very beginning. You should precisely specify what do you need this result for. It appears that I answered not to the question you had in mind. Where do you want to export it and for what purpose? What are you going to do with it in Word? Or in Editor? Sorry, I do not know matlab at all. – Alexei Boulbitch Nov 7 '19 at 9:43
• To address your claim that error message shows up. This code works for me (Mma 12, Win. 10). The reason that it made some problems for you may be that on your machine Mma "remembered" some of the used values. Try to apply Clear to all variables used in this code. – Alexei Boulbitch Nov 7 '19 at 9:45
• @xzczd That is quite possible. However, from the discussion I got an impression that the OP did not clearly formulated his final goal. It seems now that it is about export, rather than representation in Mma. It is quite probable that the solution OP needs is completely different, nothing to do with what I offered. But I propose that OP first explains his aims more clearly. – Alexei Boulbitch Nov 7 '19 at 13:46