0

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

gwr
  • 13,452
  • 2
  • 47
  • 78
S.S.
  • 350
  • 1
  • 13

3 Answers3

3

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}
]
Quantum_Oli
  • 7,964
  • 2
  • 21
  • 43
2

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" ] 
gwr
  • 13,452
  • 2
  • 47
  • 78
1

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"]
Jason B.
  • 68,381
  • 3
  • 139
  • 286