a[1] = 2;
a[2] = 4;
a[3] = 7;
E = 1.5;
l = 0.02;
Print["m                   n1              n2               n3"];
For[m = 1, m < 10, m++,
  For[i = 1, x = 0, i <= 3, i++; 
    x = (a[i] + m + E)/l;
    If[i == 1, n1 = x; i == 2, n2 = x; i == 3, n3 = x];];
  Print[m "     ", n1 "        ", n2 "       ", n3];] 

I want to get output in table format. If anyone can solve this their help will be most welcome.

Table format means I want my output to look like this:

m                  n1            n2              n3                                                                             
1                  -             -               -                                                                              
2                  -             -               -                                                                           
3                  -             -               -                                                                                                                                                                                                             

and so on up to 10 values of m.

Now if you are understanding my problem. please help me.


closed as off-topic by happy fish, Szabolcs, MarcoB, Henrik Schumacher, Alex Trounev Apr 26 at 20:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Szabolcs, MarcoB, Henrik Schumacher, Alex Trounev
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Please at least try to read the docs for correct syntax before asking. a[1] = 2; a[2] = 4; a[3] = 7; e = 1.5; l = 0.02; Print["m n1 n2 n3"]; For[m = 1, m < 10, m++, For[i = 1; x = 0, i <= 3, i++, x = (a[i] + m + e)/l; Which[i == 1, n1 = x, i == 2, n2 = x, i == 3, n3 = x];]; Print[m " ", n1 , " ", n2, " ", n3];] $\endgroup$ – happy fish Apr 19 at 7:23
  • $\begingroup$ It may help you to consider the statement Grid[Table[ f[m,i] , {m, 1, 9}, {i, 1, 3}]] . If that gives you the right size grid, then you're halfway there. After you see what Grid and Table can do for you, the next step is to define a function f[m,i] or to replace f[m,i] with an appropriate expression that gives what you want in the grid. If you get stuck, please edit your question and add your new code to show us your changes and where you are stuck. $\endgroup$ – LouisB Apr 19 at 8:58
  • $\begingroup$ Thanks @happy fish it's effective. $\endgroup$ – vijay Apr 19 at 18:29

Your input of code is appreciated, but the syntax seems to be everywhere, and nowhere that is Mathematica or WL. Please see this post, and search "for loop" at the search bar, to find out why for loops are best left out of your programming constructs:


When creating a set, such as you have attempted with a, you must declare it as a set, whereas you have been declaring the output of the function of "a" with the value applied to it within the brackets. This is like so:

a = {2, 4, 7}; Ε = 1.5; l = 0.02;

And so-on. I would kindly ask that you work on your syntax a bit from the above reference and if you should need additional advice, we can find the answer to your problem.

I hope this helps!

Edit: Don't use protected symbols like 'E', instead, if you wish to track 'E' throughout, use something like:

  • $\begingroup$ I am not getting the proper output. If you can solve this, most welcome. $\endgroup$ – vijay Apr 19 at 7:13
  • $\begingroup$ @vijay can you please clarify what the size of your table will be? Possibly add some expected output, if your syntax is lacking in what is necessitated to do so. I am trying to parse your goal, but it is difficult. I will check back later and see what I can do :D $\endgroup$ – CA Trevillian Apr 19 at 7:32
  • $\begingroup$ Now see the question again, if you can solve now. $\endgroup$ – vijay Apr 19 at 8:10

When you want to build a table in Mathematica, your 1st choice should be Table not For. Here is a simple way of making your table.

t1 = 
  Module[{a, e, l},
    a = {2, 4, 7};
    e = 1.5;
    l = 0.02;
    Table[{m, (a + m + e)/l} // Flatten, {m, 10}]];

TableForm[t1, TableHeadings -> {None, {m, n1, n2, n3}}]



The following is added to address concerns raised by the OP in a comment to this answer.

To make m run from -10 to 0, you have to write the index specification in a slightly different form. Like so.

Table[{m, (a + m + e)/l} // Flatten, {m, -10, 0}]

The index range specification must always be given in the direction toward positive infinity; lowest value 1st then highest value.

  • $\begingroup$ This code is not working. In the output only showing t1. Don't know why. By the way i am using version 9.0 $\endgroup$ – vijay Apr 19 at 18:32
  • $\begingroup$ @vijay if I am correct, you would have t1:=Module[.....and so-on for m_goldberg's answer to evaluate $\endgroup$ – CA Trevillian Apr 19 at 19:47
  • $\begingroup$ @vijay. Sorry, I forgot the assignment to t1. I have fixed the code. $\endgroup$ – m_goldberg Apr 20 at 0:33
  • $\begingroup$ Now it's working. thanks a lot. for your time. $\endgroup$ – vijay Apr 20 at 4:31
  • $\begingroup$ @m_goldberg but this not showing anything if need values upto 0 to -10. negative values of m is not showing. if you can figure it out please take a look. $\endgroup$ – vijay Apr 20 at 4:42

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