0
$\begingroup$

I don't have much experience importing data and working with it in Mathematica, so I'm writing to ask for advice. I have the following data:

 1  1.13911231E-03  1.64070004E-07  7.92799535E+07  3.26351645E+26  5.65898042E+27  1.57981001E+07  1.56353294E+02
    2.38353869E+17  1.44302116E+08  2.37442637E+08  1.66786341E+00  8.62209258E-01  5.04240617E+07  1.79099351E+01
    3.28236653E-01  2.10971719E-02  1.26956768E+00  3.62728115E-01 -1.95223862E+00  3.32192853E-01  3.96718699E-01
    1.01361838E+00  9.89125537E-01  1.00607987E+00  1.21156834E+01  8.09056541E-01  1.43272575E-08
    8.09034242E-01  1.43276523E-08  0.00000000E-01  4.40009138E+11  0.00000000E-01
 6  1.54847434E-03  4.12125218E-07  1.07770737E+08  8.19758270E+26  1.42384900E+28  1.57976983E+07  1.56339167E+02
    2.38335641E+17  1.44307850E+08  2.37452201E+08  1.66786340E+00  8.62175347E-01  5.04244114E+07  1.79082415E+01
    3.28273697E-01  2.10981645E-02  1.26964164E+00  3.62732600E-01 -1.95222877E+00  3.32776229E-01  3.96718786E-01
    1.01361782E+00  9.89126156E-01  1.00608099E+00  1.21152211E+01  4.37834482E-01  2.59652938E-08
    4.37791491E-01  2.59678435E-08  0.00000000E-01  3.23699970E+11  0.00000000E-01
11  2.10499165E-03  1.03521174E-06  1.46503236E+08  2.05913968E+27  3.57862398E+28  1.57969551E+07  1.56313083E+02
    2.38301960E+17  1.44318436E+08  2.37469857E+08  1.66786336E+00  8.62112745E-01  5.04250546E+07  1.79049136E+01
    3.28342091E-01  2.10979750E-02  1.26971657E+00  3.62743899E-01 -1.95219004E+00  3.33004741E-01  3.96718946E-01
    1.01361678E+00  9.89127298E-01  1.00608225E+00  1.21142963E+01  2.36934507E-01  4.79529245E-08
    2.36891360E-01  4.79616584E-08  0.00000000E-01  2.38147745E+11  0.00000000E-01
16  2.86160655E-03  2.60033433E-06  1.99162130E+08  5.17232501E+27  8.98976633E+28  1.57955811E+07  1.56264899E+02
    2.38239735E+17  1.44337999E+08  2.37502489E+08  1.66786330E+00  8.61997071E-01  5.04262424E+07  1.78987756E+01
    3.28468492E-01  2.10977482E-02  1.26985891E+00  3.62764610E-01 -1.95211980E+00  3.33095771E-01  3.96719241E-01
    1.01361486E+00  9.89129404E-01  1.00608466E+00  1.21125923E+01  1.28212299E-01  8.85728510E-08
    1.28169174E-01  8.86026530E-08  0.00000000E-01  1.75220952E+11  0.00000000E-01
21 ...

In which each set is denoted by the numbers "1", "6", "11", "16", ... "(n-1) + 5" contains a total of 21 + 6 + 5 = 32 parameters.

I want to extract, in each set (1,6,11,16,...), 3 parameters of interest, let's say the values (3,2+index), (4,3+index), (6,1+index) in the format (row, column), where index = 5*n, to then compute the product and get a ListPlot of its evolution.

How can I do it in a comprehensive way? The values are space separated strings. I'd be happy to add partial advances but being honest I don't know how to tackle the problem in Mathematica.

Edit:

Current attempt is

data = ArrayReshape[Import["C:/Users/User/Desktop/file.txt", "Table"],{379,33}]

So I have a list of 379 lists with 33 parameters (counting the index of each set). What should I do next so I can compute the product and put it in a new list of products?

Now I know that I can access to values of data using

data[[i]][[j]]

so the task would be to iterate

product[i] = data[[i]][[3]]*data[[i]][[5]]*data[[i]][[6]]

assuming the interest on the values in columns 3,5,6. How can I iterate this, e.g., in a for cycle, adding each product to a List of products?

Listofproducts = [product[1],product[2],...]

EDIT2: The final step can be done using:

product = {}
Do[val1 = data[[i]][[3]]; val2 = data[[i]][[5]]; 
 val3 = data[[i]][[6]]; 
 AppendTo[product, val1*val2*val3], {i, 379}]

And this would be a way to tackle the problem, finally.

The results are the following:

Intensity ratios calculated using the inverse of product of opacity, radius and density

For single parameters:

The Do iteration can also extract parameters of each layer to be plotted then. These are results for radius, opacity and density of a star, obtained from the YREC6 code of Star evolution, from YALE

I'll keep the question if anyone want to answer in a different / more effective way :)

$\endgroup$
  • $\begingroup$ Well, there doesn't exist (6,1+index) in each set, does it? $\endgroup$ – xzczd Sep 22 at 1:52
  • $\begingroup$ @xzczd the original idea was to jump 5 rows for a new set (from 1 to 6) above the current one. Anyways I could solve that fixing all the 32 parameters in 1 list. $\endgroup$ – holahola Sep 22 at 7:36
  • 1
    $\begingroup$ Doesn't product=data[[All,3]]*data[[All,5]]*data[[All,6]] do what you want? Alternatives include Times@@@data[[All,{3,5,6}]] or #3*#5*#6&@@@data $\endgroup$ – Lukas Lang Sep 23 at 19:11
  • $\begingroup$ @LukasLang Indeed that's a better way to do it. This also implies that I could've used data_3 = data[[All,3]] to extract all the information of a single parameter right? I appreciate a lot your comment!. $\endgroup$ – holahola Sep 23 at 21:10
  • 1
    $\begingroup$ @holahola Yes, data[[All,3]] does exactly that $\endgroup$ – Lukas Lang Sep 23 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.