0
$\begingroup$

I have a code that goes like this:

ClearAll["Global`*"]

const1 = 2.;
\[Kappa] = 23;

tbl = Table[{x, N[x^(1/2)], 0 x, N[x^(1/3)], 0 x, N[x^(1/4)], 0 x, 
    N[x^(1/5)], 0 x}, {x, 2, 20, 2}];

SetDirectory[NotebookDirectory[]];

newrow[{a_, b_, c_, d_, e_, f_, g_, h_, i_}] := {a, b, c, (
   Sqrt[\[Pi]]*b* const1 Exp[-(b^2/(2 Sqrt[a]))])/(const1 \[Kappa]^5),
    d, e, (Sqrt[\[Pi]]*d *onst1 Exp[-(d^2/(2 Sqrt[a]))])/(
   const1 \[Kappa]^5), f, g, (
   Sqrt[\[Pi]]*f *const1 Exp[-(f^2/(2 Sqrt[a]))])/(const1 \[Kappa]^5),
    h, i, (Sqrt[\[Pi]]*h *const1 Exp[-(h^2/(2 Sqrt[a]))])/(
   const1 \[Kappa]^5)};
newtbl = Map[newrow, tbl];
headings = {"x", "real1", "imag1", "col1manipulated", "real2", 
   "imag2", "col2manipulated", "real3", "imag3", "col3manipulated", 
   "real4", "imag4", "col4manipulated"};
Export["file1.dat", Join[{headings}, newtbl]];

Once the table, tbl, is created, I am taking the data from each column and use it to do some arithmetic operation.

  1. Now, as you can see, I have a term $\frac{\sqrt{\pi}*b*const1*e^{\frac{-b^2}{2\sqrt{a}}}}{const1*κ^5 }$ which repeats multiple time but with only one factor changing, namely, b or d or f or h. If I am writing individual terms all the times, the code becomes messy. Is there any way to simply it? E.g. define something like $\frac{\sqrt{\pi}*i*const1*e^{\frac{-i^2}{2\sqrt{a}}}}{const1*κ^5 }$ outside and call it inside every time?
  2. In the code which gives me heading, I have to write "real1","imag1","col1manipulated" and then "real2","imag2","col2manipulated" so on. Is there any way to simplify this? Like to make "real1","imag1","col1manipulated" till "real5","imag5","col5manipulated" by some command and then append it?

Thanks in advance.

$\endgroup$
2
$\begingroup$

revised

fun[v_] := Sqrt[\[Pi]] v const1 Exp[-b^2/(2 Sqrt[a])]/(const1 \[Kappa]^5);
newrow[{a_, b_, c_, d_, e_, f_, g_, h_, i_}] := 
  {a, b, c, fun[b], d, e, fun[d], f, g, fun[f], h, i, fun[h]};
heading=Flatten[{"x", Table[str=ToString[i];
  {"real"<>str,"imag"<>str,"col"<>str<>"manipulated"},{i,1,4}]}] 
$\endgroup$
2
  • $\begingroup$ you are almost there. In heading, I need to put "x" one and only time, which you have not done it. If I am putting it inside {"real"<>str..."manipulated"}, it is getting repeated 5 times. What more can be done? Also kindly check the question, I made a mistake in "headings": "real3", "imag3", "col3manipulated" was missing and I have deleted "real5", "imag5", "col5manipulated". Question has been edited. $\endgroup$
    – sreeraj t
    May 6 '19 at 2:52
  • $\begingroup$ thanks you.. this is it.. $\endgroup$
    – sreeraj t
    May 6 '19 at 5:29

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.