If my function is

LUM[x1_, x2_] := Module[{l = x1, v = x2},
  T = (4*l*h*f)/(me*c^2);
  Tq = h*v/((l*me*c^2) - h*v);
  q = Tq/T;
  upper = q*f*4.0*l^2;
  lower = q*f;
  F = (2 q*Log[q] + (1 + 2 q) (1 - q) + ((Tq^2)*(1 - q))/(2*(1 + Tq)));
  n = (8*Pi*f^2/c^3)*((1/(Exp[h*f/(k*Tcmb)] - 1))
        + (Nsl/(Exp[h*f/(k*Tsl)] - 1))
        + (Nir/(Exp[h*f/(k*Tir)] - 1)));
  f = 10.0^uf;
  data = Table[{uf, F*n}, {uf, Log[10, lower], Log[10, upper], 0.05}];
  lum = Integrate[
    Interpolation[data, InterpolationOrder -> 2][uf],
    {uf, Log[10, lower], Log[10, upper] - 0.1}

and I want to change x2 that have a lot of values and If I want to write loop to find LUM. How can I write and store value from LUM?

  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Aug 21, 2015 at 17:46
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$
    – Michael E2
    Aug 21, 2015 at 17:46
  • $\begingroup$ Look up the documentation for Table. $\endgroup$
    – march
    Aug 21, 2015 at 17:48
  • $\begingroup$ Thank you,everyone for your help $\endgroup$
    – Noey-Jaru
    Aug 21, 2015 at 18:00
  • $\begingroup$ Can I ark u more? after that I will do many thing and I wonder about store value from loop by use 'for' . I find it on internet but it's not work for me. Can u write in by loop for example to me? I want it print by vector form e.g. {x2,LUM} $\endgroup$
    – Noey-Jaru
    Aug 21, 2015 at 18:25

1 Answer 1


At the moment the LUM function as written can't be used because it depends upon a number of global variables (h, me, k, Tcmd ...) that you have not supplied.

However, in order to produce a list of {x2, LUM[x1,x2]} pairs this can be done as follows.


Assume x2List is the list of values that you want to evaluate and you want to evaluate LUM at a discrete (i.e., scalar) value for x1.

x2List = {1, 2, 3, ...}

Then one could use Table

Table[{x2, LUM[x1, x2]}, {x2, x2List}]

to produce the result.

Another approach would be to use Map with a pure function

Map[{#, Lum[x1, #]} &, x2List]


If you want to have the results be pairs of {x2, LUM[x1List, x2} where x1List is a list of x1 values (i.e, a vector) you do exactly the same operation except you set the attributes of LUM to be listable.

SetAttributes[LUM, Listable]

and then

 Table[{x2, LUM[x1List, x2]}, {x2, x2List}]


Map[{#, Lum[x1List, #]} &, x2List]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.