evyrl66

Programming

Math

University College London (UCL)

### Question Description

Do following questions in matlab. Due in 9 days.

Do following questions in matlab. Due in 9 days.

### Unformatted Attachment Preview

Purchase answer to see full attachment

## Final Answer

What's up? I've finished the assignment, files in attachment are:.nb -> Mathematica notebook files.pdf -> Printable versions of the .nb'sending with Unev -> Unevaluated version, just the codeending with Ev -> Evaluated version (all the code was evaluated, has all the graphs and variables)If you have any questions or need anything else, please feel free to ask.

In[399]:=

Print["Item 1"]

Print["Norm[{2,0}] = ", Norm[{2, 0}]]

Print["Norm[{2,1}] = ", Norm[{2, 1}]]

Item 1

Norm[{2,0}] = 2

Norm[{2,1}] =

In[402]:=

5

Print["Item 2"]

colorList = TableHuei 25, Point[{i, Sin[i]}], {i, 1, 25}

Item 2

Out[403]=

In[404]:=

{{

{

{

{

{

{

{

{

{

,

,

,

,

,

,

,

,

,

Point[{1, Sin[1]}]}, {

Point[{3, Sin[3]}]}, {

Point[{6, Sin[6]}]}, {

Point[{9, Sin[9]}]}, {

Point[{12, Sin[12]}]},

Point[{14, Sin[14]}]},

Point[{17, Sin[17]}]},

Point[{20, Sin[20]}]},

Point[{23, Sin[23]}]},

,

,

,

,

{

{

{

{

{

Point[{2, Sin[2]}]},

Point[{4, Sin[4]}]}, { , Point[{5, Sin[5]}]},

Point[{7, Sin[7]}]}, { , Point[{8, Sin[8]}]},

Point[{10, Sin[10]}]}, { , Point[{11, Sin[11]}]},

, Point[{13, Sin[13]}]},

, Point[{15, Sin[15]}]}, { , Point[{16, Sin[16]}]},

, Point[{18, Sin[18]}]}, { , Point[{19, Sin[19]}]},

, Point[{21, Sin[21]}]}, { , Point[{22, Sin[22]}]},

, Point[{24, Sin[24]}]}, { , Point[{25, Sin[25]}]}}

Print["Item 3"]

Print["Graphics[colorList]"]

Graphics[colorList]

Print["Graphics[colorList, Axes→True]"]

Graphics[colorList, Axes → True]

Item 3

Graphics[colorList]

Out[406]=

Graphics[colorList, Axes→True]

1.0

Out[408]=

-1.0

In[409]:=

10

15

20

25

Print["Item 4"]

a := RandomVariate[NormalDistribution[0, 1]]

b := {a, a}

Print["Variables a and b were created successfully."]

Print["Examples -> a: ", a, ", b: ", b]

Item 4

Variables a and b were created successfully.

Examples -> a: 0.599055, b: {-0.275378, -0.515623}

In[414]:=

Print["Item 5"]

walk2D[n_] := NestWhileList[# + b &, {0, 0}, Norm[#] < n &]

Print["Function walk2D created successfully."]

Print["Example -> walk2D[3]: ", walk2D[3]]

2

Math01Ev.nb

Item 5

Function walk2D created successfully.

Example -> walk2D[3]: {{0, 0}, {1.34494, 0.797894}, {0.465819, -0.400476},

{-0.316588, -0.275931}, {-1.40361, 0.352398}, {-2.60838, 0.236823},

{-2.1572, -0.514527}, {-2.49219, -1.32489}, {-2.82282, -1.46884}}

In[418]:=

Print["Item 6"]

addColor[myList_] := Module{m},

m = Length[myList];

TableHuei m, Point[myList[[i]]], {i, 1, m}

Print["Function addColor created successfully."]

Print["Example with the list {{2,0},{2,1}}"]

addColor[{{2, 0}, {2, 1}}]

Item 6

Function addColor created successfully.

Example with the list {{2,0},{2,1}}

Out[422]=

{{ , Point[{2, 0}]}, { , Point[{2, 1}]}}

In[423]:=

Print["Item 7"]

walkList = Table[walk2D[100], {20}]

Print["Variable walkList created successfully."]

Item 7

Out[424]=

{0, 0}, {- 0.846301, 0.651076}, {- 3.11587, 2.52302},

{- 4.49308, 2.83021}, {- 5.23227, 1.06317}, {- 3.82052, 1.7278},

{- 3.11877, 2.74399}, {- 4.08066, 3.50055}, {- 3.9096, 5.08908}, ⋯ 1506 ⋯ ,

{- 94.1458, - 23.3685}, {- 93.1996, - 23.543}, {- 93.4217, - 23.4482},

{- 92.4445, - 23.1849}, {- 94.2092, - 23.3653}, {- 94.1264, - 23.186},

{- 94.8156, - 23.0688}, {- 95.0994, - 24.2428}, {- 98.5425, - 25.8824}, ⋯ 19 ⋯

large output

show less

show more

show all

set size limit...

Variable walkList created successfully.

In[426]:=

Print["Item 8"]

lengthList = Table[Length[walkList[[i]]], {i, 1, 20}]

meanLength = N[Mean[lengthList]]

medianLength = N[Median[lengthList]]

Print["The random walks have a mean length of ",

meanLength, " and a median length of ", medianLength]

Item 8

Out[427]=

{1524, 6363, 2876, 5533, 3085, 4758, 7023, 1979, 2738,

2958, 1000, 1222, 3407, 2136, 2930, 12 990, 9494, 4588, 2322, 5731}

Out[428]=

4232.85

Out[429]=

3021.5

The random walks have a mean length of 4232.85 and a median length of 3021.5

Math01Ev.nb

In[431]:=

Print["Item 9"]

Manipulate[Graphics[addColor[walkList[[i]]], Axes...