Wolfram language understanding

Hi, folks, I’m now a proud owner of a full Mathematica licence and trying to understand the language. Actually I’ll understand the following, small program:

Euler[a0_, b0_, steps0_, x0_, v0_] := 
 Module[{a = a0, b = b0, steps = steps0, xinit = x0, vinit = v0}, 
  dt = (b - a)/steps;
  k = 5.0;
  m = 2.0;
  c = 0.5;
  f[{t_, x_, v_}] := v;
  g[{t_, x_, v_}] := -x (k/m) - c v;
  euler[{t_, x_, v_}] := {t + dt, x + dt f[{t, x, v}], 
    v + dt g[{t, x, v}]};
  NestList[euler, {a, xinit, vinit}, steps]]
result = Euler[0, 20, 100000, 1, 1];
ListPlot[{result[[All, 2]], result[[All, 3]]}, PlotRange -> All]

I’ve no idea, why obviously the function values of curve 1 are stored in
result[[All, 2]] and the values of curve 2 in result[[All, 3]]. Every hints, where I can find further information ( books?) are highly appreciated! Thank you very much!

Peter

obviously it is not readable, what I’ve written - sorry!

Please check http://community.wolfram.com/groups/-/m/t/151347 for formatting suggestions.

I’m not quite sure what you’re asking, but I’ll have a go.

After some initializing, the euler[{t_, x_, v_}] := “function” takes three values and returns a list of three values. The first is basically an x-coordinate, the second and third are some values.

The NestList[euler … expression applies this euler “function” repeatedly, keeping each of the three-valued lists as it goes through the required number of steps. The result returned by the module is a long list of three-element lists. If you leave off the semicolon at the end of result = Euler[0., 20, 100000, 1, 1] you’ll see part of the huge list. The first element in each of the three-element lists is not really needed for plotting (with ListPlot at least, which assumes the y-values are in order so that you don’t have to supply any x-coordinates). Each second element is the result of x + dt f[{t, x, v}], and the third is the result of v + dt g[{t, x, v}] (whatever they are). Then result[[All, 2]] is like asking for ‘every row, second column’ of a table, and result[[All, 3]] gets the third column. (A useful way of thinking about 2D lists of lists.)

As for recommendations, there’s really no shortage of information, either online or in book form - or even video (visit Wolfram Video Archive or YouTube). Most of the books you find for sale don’t apply to the current version, but the basics of Mathematica haven’t changed hugely. I first became interested in Mathematica when I bought S.Wolfram’s tome “Mathematica - a System for Doing Mathematics by Computer” from a second-hand bookshop for 99p (ie less than 1 UK pound). (I bought it for the pictures.)

Hi, C ormullion,
thanks a lot for your answer. I’ll search and try to find further infos to understand WL!
Peter