0
$\begingroup$
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.

$\endgroup$
3
  • 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$ Commented Apr 19, 2019 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$ Commented Apr 19, 2019 at 8:58
  • $\begingroup$ Thanks @happy fish it's effective. $\endgroup$ Commented Apr 19, 2019 at 18:29

1 Answer 1

1
$\begingroup$

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:

Ε
$\endgroup$
3
  • $\begingroup$ I am not getting the proper output. If you can solve this, most welcome. $\endgroup$ Commented Apr 19, 2019 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$ Commented Apr 19, 2019 at 7:32
  • $\begingroup$ Now see the question again, if you can solve now. $\endgroup$ Commented Apr 19, 2019 at 8:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.