0
$\begingroup$

I have the following formulas:

1- A cross section:

sigma[beta_,alpha_,Y4_] := c^2/(256*Pi) * (1/2) ( Ytt[beta,alpha,Y4]/ m ) * Abs[A]^2 

Where c is a strong coupling constant, m is a mass, A is a loop function and Ytt[beta,alpha,Y4] is a coupling .

2- A final cross sectionfsigma, which equals sigma times a branching ratio BR, that:

fsigma[beta_,alpha_,Y4_,xx_,ms_] := sigma[beta,alpha,Y4] * BR[beta,alpha,Y4,xx,ms]

I 'd like to generate a data file (.dat file), for the values of fsigma runs over the five free parameters, with each parameter has a region, as:

{beta,ArcTan[0.9],ArcTan[2.],0.1}, {alpha,ArcTan[0.1],ArcTan[0.3],0.1}, {Y4,-1,-5,1},{xx,-7,7,1},{ms,350,400,50}

Also can I before making this loop, to set a pre- defined constrain on Ytt[beta,alpha,Y4] => 0.8 < Ytt[beta,alpha,Y4] < 1.2. i.e., to select from the parameters domains only the points which satisfy this constrain.

I tried to use Do loop with If condition, but it doesn’t work for me

$\endgroup$
1
$\begingroup$

You can generate a table from a loop using Reap and Sow

results =
    Reap[
      Do[
       If[0.8 < Ytt[beta, alpha, Y4] < 1.2,
        Sow[{beta, alpha, Y4, xx, ms, fsigma[beta, alpha, Y4, xx, ms]}]
        ],
       {beta, ArcTan[0.9], ArcTan[2.], 0.1},
       {alpha, ArcTan[0.1], ArcTan[0.3], 0.1},
       {Y4, -1, -5, -1},
       {xx, -7, 7, 1},
       {ms, 350, 400, 50}
       ]
      ][[2, 1]];~Monitor~{beta, alpha, Y4, xx, ms};
Export["results.dat", results, "Table"]
$\endgroup$
  • $\begingroup$ @S.S. Sorry, see edit. Try Export["results.dat", results, "Table"] $\endgroup$ – Jason B. May 20 '16 at 15:24
  • $\begingroup$ I found results.dat has been made , but only with one word "Table". $\endgroup$ – S.S. May 20 '16 at 15:28
  • $\begingroup$ Thanx, it's working now. $\endgroup$ – S.S. May 20 '16 at 15:30
  • $\begingroup$ @ JasonB. Can I set extra constrain on fsigma[beta, alpha, Y4, xx, ms] to list only the values where fsigma[beta, alpha, Y4, xx, ms] > 0 ? $\endgroup$ – S.S. May 20 '16 at 16:21
  • $\begingroup$ @S.S. Easy, just use (0.8 < Ytt[beta, alpha, Y4] < 1.2)&&fsigma[beta, alpha, Y4, xx, ms] >0 $\endgroup$ – Jason B. May 20 '16 at 18:11
3
$\begingroup$

You're probably better off using something like Table than an explicit For or Do loop (I believe this is often the case in MMA). e.g:

Table[{
    beta, alpha, Y4, xx, ms, 
    If[ 0.8 <= Ytt[beta, alpha, Y4] < 1.2, fsigma[beta, alpha, Y4, xx, ms] , 0]},
  {beta, ArcTan[0.9], ArcTan[2.], 0.1},
  {alpha, ArcTan[0.1], ArcTan[0.3], 0.1}, 
  {Y4, -1, -5, -1},
  {xx, -7, 7, 1},
  {ms, 350, 400, 50}
]
$\endgroup$
  • $\begingroup$ I think it's better to use a loop, for my expressions $\endgroup$ – S.S. May 20 '16 at 8:48
2
$\begingroup$

Expanding upon the answers so far you may have a nice format for output on screen (e.g. Dataset) and get your file as you want it.

Creating a Dataset

data = Table[
    (* List elements *)
    If[ 0.8 <= Ytt[ beta, alpha, Y4 ] < 1.2,
        (* then *) Association[
            "beta" -> beta,
            "alpha" -> alpha,
            "Y4" -> Y4,
            "xx" -> xx,
            "ms" -> ms,
            "fsigma" -> fsigma[ beta, alpha, Y4, xx, ms ]
        ],
        (* else *) Nothing (* which is automatically removed *)
    ],
    (* iterator specification *)
    {beta, ArcTan[0.9], ArcTan[2.], 0.1},
    {alpha, ArcTan[0.1], ArcTan[0.3], 0.1}, 
    {Y4, -1, -5, -1},
    {xx, -7, 7, 1},
    {ms, 350, 400, 50}
] // RightComposition[
        Flatten[ #, 2]&, (* bring the Table-results to just 2 levels and have Nothing removed *)
        Dataset
    ] 

Exporting the Values to a File

Using Normal and Values you can use Export to export the revant values to a .dat file as demonstrated by JasonB.

(* SetDirectory[ NotebookDirectory[] ] or something else if needed *)
Export[ "data.dat", data[[ All, Values ]]//Normal, "Table" ] 
$\endgroup$
  • $\begingroup$ If you would like to view the dataset but find it is too large, this will help. $\endgroup$ – gwr May 20 '16 at 11:07

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.