Group Abstract Group Abstract

Message Boards Message Boards

Access to Roman Maeder's Package for Computational Science with Mathematica

Dear community members, I just started reading Roman Maeder's book "Computer Science with Mathematica" and I'd like to do the computations along but unfortunately the page to download the CSM package is no longer available: http://www.mathconsult.ch/en/showroom/pubs/CSM

Does anybody know an alternative way to have access to the Mathematica package?

Many thanks in advance.

14 Replies
Posted 5 years ago

Knapsack:

größe[element_] := element[[1]]
wert[element_] := element[[2]]

total[knapsack_, wg_] := Plus @@ wert /@ wg[[knapsack]]   (*Wert*)
inhalt[knapsack_, wg_] := Plus @@ größe /@ wg[[knapsack]]   (*Gewicht*)

Knapsack[{}, g_Integer?NonNegative] := {}

Knapsack[wg_List, g_Integer?NonNegative] := 
 Module[{gn = größe[Last[wg]], wn = wert[Last[wg]], n = Length[wg], 
   rest = Drop[wg, -1], k1, k2}, 
  k1 = Knapsack[rest, g];(*ohne letzten Gegenstand*)
  If[g >= gn, k2 = Knapsack[wg, g - gn];(*mit letztem Gegenstand*)
   k2 = Append[k2, n];
   If[total[k1, wg] >= total[k2, wg], k1, k2], k1]]

KnapsackGraph[{}, 
  inhalt_Integer?NonNegative] := {{}, {knoten[{inhalt, 0}, 0]}}

KnapsackGraph[wg_List, inhalt_Integer?NonNegative] := 
 Module[{gn = größe[Last[wg]], wn = wert[Last[wg]], n = Length[wg], 
   rest = Drop[wg, -1], k1, k2, g, k, g1, g2}, {k1, g1} = 
   KnapsackGraph[rest, inhalt];
  If[inhalt >= gn, {k2, g2} = KnapsackGraph[wg, inhalt - gn];
   k2 = Append[k2, n];
   If[total[k1, wg] >= total[k2, wg], k = k1; 
    g = {arrow[{inhalt, n}, {inhalt, n - 1}, True], 
      arrow[{inhalt, n}, {inhalt - gn, n}]}, k = k2; 
    g = {arrow[{inhalt, n}, {inhalt, n - 1}], 
      arrow[{inhalt, n}, {inhalt - gn, n}, True]}], k = k1; 
   g = {arrow[{inhalt, n}, {inhalt, n - 1}, True]};
   g2 = {};];
  {k, Join[g, g1, g2, {knoten[{inhalt, n}, total[k, wg]]}]}]

diskr = 0.4;                             (*Disk Radius*)
sf = 2;                                  (*vertical scaling*)
scale[{x_, y_}] := {x, sf y}
knoten[xy_List, text_] := {{GrayLevel[1], Disk[scale[xy], diskr]}, 
  Circle[scale[xy], diskr], Text[text, scale[xy]]}

t0 = 0.4; t1 = 1.1;(*Thickness[] in Punkten*)
arrow[from_, to_, 
  fett_ : False] := {AbsoluteThickness[If[fett, t1, t0]], 
  Line[{scale[from], scale[to]}]}

xticks[min_, max_] := Range[Round[min + 1], Round[max - 1], 2]
yticks[min_, max_] := 
 Table[{i, i/2}, {i, Round[sf (min + 1)], Round[sf (max - 1)], sf}]

KnapsackPlot[wg_List, inhalt_Integer?NonNegative, opts___] := 
 Module[{gr}, gr = KnapsackGraph[wg, inhalt][[2]];
  Show[Graphics[gr], opts, Frame -> True, AspectRatio -> Automatic, 
   FrameLabel -> {"g", "n"}, 
   PlotRange -> {{-1, inhalt + 1}, {-1, sf Length[wg] + 1}}, 
   FrameTicks -> {xticks, yticks, xticks, yticks}]]

Iterative Version:

KnapsackIterative[wg_List, inhalt_Integer?NonNegative] := 
 Module[{ks}, ks[0, in_] = {};
  ks[n_, in_] := 
   ks[n, in] = 
    Module[{gn = größe[wg[[n]]], wn = wert[wg[[n]]], k1, k2}, 
     k1 = ks[n - 1, in];
     If[in >= gn, k2 = ks[n, in - gn]; k2 = Append[k2, n];
      If[total[k1, wg] >= total[k2, wg], k1, k2], k1]];
  ks[Length[wg], inhalt]]

Examples:

sizes = {3, 4, 7, 8, 9};
values = {4, 5, 10, 11, 13};
things = {sizes, values}\[Transpose];
KnapsackPlot[things, 17]
POSTED BY: Oliver Seipel

Hi Oliver,

great! Thank you once again!

Philipp

POSTED BY: Philipp Winkler

Hi Oliver,

I don't know what to say. Thank you very much!! I really appreciate your help!

Happy new year!

Philipp

POSTED BY: Philipp Winkler
Posted 5 years ago
POSTED BY: Oliver Seipel

Actually I missed a file which I cannot retype completely:

Chapter 7 - KnapG.m (the graphical version of Knapsack - especially KnapsackPlot would be interesting)

Thank you very much!

POSTED BY: Philipp Winkler

That is very nice. Book "Informatik für Mathematiker und Naturwissenschaftler":

Chapter 6.2: QSortG.m - the graphical Version of Q-Sort

Chapter 6.3: the implementation of BaumPlot would be interesting. The rest of BinBaum.m I can retype.

Chapter 8.4.2: Function HeapPlot

Chapter 12: TuringR.m

Chapter B.2: Heureka.m

Thank you very much for your effort!

POSTED BY: Philipp Winkler
Posted 5 years ago

If you tell me which chapter you are interested in, I can try to reconstruct the missing code.

POSTED BY: Oliver Seipel
Posted 5 years ago

This book is based on an older book (written in german) by the same author from 1993 "Informatik für Mathematiker und Naturwissenschaftler". As far as I can see it is just a translation.

I own the 1993 german book, but sadly the source code messes up with the german "Umlaut" i.e. ä, ö. ü on my recent computer.

But as far as i can see there are only a few packages. The most part is printed in the book, so it can be retyped. (I did this for FunctionIteration and BinaryTree)

Here is the (slightly edited (good for more recent Mathematica version)) code for FunctionIteration:

FunctionIteration[f_, x0_, initial_ : 0, length_, {xmin_, xmax_}, 
  opts___] :=
     Module[{start, orbits, plot, lines, x},
          start = Nest[f, N[x0], initial];
          If[ Head[start] =!= List, start = {start} ];
          orbits = Transpose[ NestList[f, start, length] ];
          plot = Plot[f[x], {x, xmin, xmax}];
          lines = Line[Partition[
                         Flatten[Transpose[{#, #}], 1], 2, 1]] & /@ 
    orbits;
          Show[ plot,
                 Graphics[{Thickness[.0001],  PointSize[.02],
                             lines, Point[{#, #}] & /@ start,
                             Line[{{xmin, xmin}, {xmax, xmax}}]}],
                 opts,
                 AxesOrigin -> {xmin, xmin},
                 PlotRange -> {{xmin, xmax}, {xmin, xmax}},
                 AspectRatio -> 1
           ]
      ]

and here is an example:

FunctionIteration[4 # (1 - #) &, {0.099, 0.1, 0, 0.101}, 0, 4, {0, 1}]

which gives: enter image description here

and NewtonIeration:

NewtonIteration[f_, x0_, length_, {xmin_, xmax_}, opts___] :=
     Module[{start = x0, xvals, plot, lines, x, fp = f'},
          If[ Head[start] =!= List, start = {start} ];

  xvals = Transpose[ NestList[# - f[#]/fp[#] &, start, length] ];
          plot = Plot[f[x], {x, xmin, xmax}];

  lines = Line[Partition[Flatten[{#, 0, #, f[#]} & /@ #, 1], 2]] & /@ 
    xvals;
          Show[ plot,
                 Graphics[{Thickness[.0001],  PointSize[.02],
                             lines, Point[{#, 0}] & /@ start}],
                 opts
           ]
      ]

with an example:

NewtonIteration[Cos, 0.5, 3, {0, 3}]
POSTED BY: Oliver Seipel

Thank you for your reply. I bought this book also and agree that „Informatik für Mathematiker und Naturwissenschaftler“ is in some way the German version of „Computer Science with Mathematica“. The book was used and the disk was unfortunately not included. I got a new copy of Computer Science with Mathematica and therefore it is a little bit frustrating that the packages cannot be obtained anymore. It is true that a lot of coding is printed in the book and can be retyped but not all coding is included.

As far as I know the file in question is called CSM1.zip.

POSTED BY: Philipp Winkler

I checked to see if I had the software on my hard drive -- I bought the book when it was new. Unfortunately, I no longer have it.

I looked at the book. It was written for version 4, so there is quite a bit that is obsolete. Someone who is experienced with Mathematica could figure out what the good bits are, but a beginner might find it hard going. Surprisingly, some of Roman's earlier books fare better, because he concentrates on basic programming in them, and that part has changed relatively little from version 1, certainly 2.2.

Some years ago, I tried to update a Mathematica book that I liked, but which was obsolete. There was so much to change, that what I ended up with was an entirely different book, which is not what I was after.

My suggestion is that you try reading the book for the ideas, and then try implementing them in current Wolfram Language syntax. The code in the book may point in the right direction in many cases, but there are quite a few things that will just bite you if you try to implement them as written.

I am beginning to think that Knuth was right (as usual): put all the actual code in a generic pseudo-code and force the reader to figure out the implementation. Not much good if you just want quick answers, but more edifying in the long run. You could treat the code in the book as a kind of pseudo-code that resembles Wolfram Language.

good luck.

True, there is nothing to download from the publisher's webpage. Have you already tried to email the publisher or the author? Here are the public contact details:

mc-enquiries@mathconsult.ch (tel. +41 44 687 4051)

lecturers@cambridge.org (tel. +44 1223 358 331)

EDIT: i made a few phone calls and the information is that the original code/packages are not fully compatible with the latest Mathematica versions which is why the author prefers to not see the material being posted/shared/distributed publicly anymore. However, if you were to send an email to the above .ch address, he would be happy to share the material (via email attachment) confidentially with you. You are allowed to use it privately but you'd have no permission to share it further. Best i could do, raspi

POSTED BY: Raspi Rascal

Thanks for the suggestion. I actually sent an email to both, the publisher and the author but I didn't get any reply. That's why I decided to post the message in the group.

Did you have any luck getting the CSM packages? I also sent a few emails to the addresses above, but didn't get any response. I am very interested in the packages. It doesn't matter if they are not fully compatible with the latest version.

POSTED BY: Philipp Winkler

Unfortunately not.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard