0
$\begingroup$

I am using Mathematica 11.

I need to run the following code,

n = 100;
task3a = Table[0, {i, 1, 10}, {j, 1, n}];
For[i=1, i<11, i++
    For[j=2, j<=n, j++,
        If[RandomInteger[]==1, s=1, s=-1];
        task3a[[i,j]]=task3a[[i,j-1]]+s;
        ]
    ]
MultipleListPlot[task3a, PlotJoined->True,
    PlotStyle->{Blue, Red, Green, Black, Yellow, Orange, Cyan, Brown, Magenta, Pink},
    SymbolShape->None]

But, the following commands are not working,

Needs["Graphics`"]
<< Graphics `MultipleListPlot`

Error Message:

Get::noopen: Cannot open Graphics`.
Needs::nocont: Context Graphics` was not created when Needs was evaluated.
$\endgroup$
  • $\begingroup$ Graphics` is an obsolete package, I believe from V5 or earlier. Most if not all of its functionality is already buildt-in now. Function names or syntax may have changed though. $\endgroup$ – Sjoerd C. de Vries Nov 20 '16 at 18:43
4
$\begingroup$

You can get this code to work by replacing MultipleListPlot with ListLinePlot, removing the SymbolShape and PlotJoined options, and adding the missing comma after i++:

n = 100;
task3a = Table[0, {i, 1, 10}, {j, 1, n}];
For[i = 1, i < 11, i++, 
   For[j = 2, j <= n, j++, 
     If[RandomInteger[] == 1, s = 1, s = -1];
     task3a[[i, j]] = task3a[[i, j - 1]] + s;]
]
ListLinePlot[task3a, PlotStyle -> {Blue, Red, Green, Black, Yellow, Orange, Cyan, Brown, Magenta, Pink}]

Mathematica graphics

But a shorter way to do this is

ListLinePlot[Prepend[0] /@ Accumulate /@ RandomChoice[{-1, 1}, {10, 99}]]

Mathematica graphics

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy