0
$\begingroup$

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

$\endgroup$
9
  • $\begingroup$ 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. $\endgroup$ – xzczd Nov 6 '19 at 13:33
  • $\begingroup$ i don't konw how to repalceall about the [,-> and some specific characters $\endgroup$ – dcydhb Nov 6 '19 at 13:48
  • $\begingroup$ Now read the document of Rule and Equal, and read this Chinese tutorial: note.youdao.com/ynoteshare1/… especially the 函数和它的马甲 section. $\endgroup$ – xzczd Nov 6 '19 at 13:50
  • $\begingroup$ 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 $\endgroup$ – Bob Hanlon Nov 6 '19 at 14:05
  • $\begingroup$ @Bob Hanlon,it seems that i want to use =and delete [ and ] $\endgroup$ – dcydhb Nov 6 '19 at 14:14
2
$\begingroup$

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]]

enter image description here

Have fun!

$\endgroup$
6
  • $\begingroup$ 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. >> $\endgroup$ – dcydhb Nov 7 '19 at 2:05
  • $\begingroup$ 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. $\endgroup$ – dcydhb Nov 7 '19 at 2:07
  • 1
    $\begingroup$ 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. $\endgroup$ – Alexei Boulbitch Nov 7 '19 at 9:43
  • 1
    $\begingroup$ 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. $\endgroup$ – Alexei Boulbitch Nov 7 '19 at 9:45
  • 1
    $\begingroup$ @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. $\endgroup$ – Alexei Boulbitch Nov 7 '19 at 13:46

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.