# Making a table and displaying it in table form [closed]

a = 2;
a = 4;
a = 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 TrounevApr 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.

• Please at least try to read the docs for correct syntax before asking. a = 2; a = 4; a = 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];] – happy fish Apr 19 at 7:23
• 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. – LouisB Apr 19 at 8:58
• Thanks @happy fish it's effective. – vijay Apr 19 at 18:29

## 2 Answers

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:

https://mathematica.stackexchange.com/a/259/63039

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:

Ε

• I am not getting the proper output. If you can solve this, most welcome. – vijay Apr 19 at 7:13
• @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 – CA Trevillian Apr 19 at 7:32
• Now see the question again, if you can solve now. – 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}}] ### Update

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.

• This code is not working. In the output only showing t1. Don't know why. By the way i am using version 9.0 – vijay Apr 19 at 18:32
• @vijay if I am correct, you would have t1:=Module[.....and so-on for m_goldberg's answer to evaluate – CA Trevillian Apr 19 at 19:47
• @vijay. Sorry, I forgot the assignment to t1. I have fixed the code. – m_goldberg Apr 20 at 0:33
• Now it's working. thanks a lot. for your time. – vijay Apr 20 at 4:31
• @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. – vijay Apr 20 at 4:42