Do following questions in matlab

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

MATH 9 HOMEWORK 4 SUMMER 2019 We will investigate 2-dimensional random walks with steps {x, y}, where x and y are normally distributed random variables. (1) Evaluate Norm[{2, 0}] and Norm[{2, 1}]. Norm represents the distance to the origin. (2) Make a length 25 list called colorList that in position i is equal to {Hue[i/25],Point[{i,Sin[i]}]}. For example, if you evaluate colorList[[5]], you should see {Hue[1/5],Point[{5,Sin[5]}]} (3) Evaluate Graphics[colorList] and Graphics[colorList,Axes − > True] (4) Define the following variables using delayed assignment (:=) a:= RandomVariate[NormalDistribution[0,1]] (This gives a random number where the average (mean) is 0 and the standard deviation (amount of variation) is 1. b:= {a,a} (5) Use NestWhileList to define a function walk2D[n ] that takes as input a number n and as output produces a 2-dimensional random wlak that begins at {0, 0} and keeps adding b until the norm (as in question 1 above) is >= n. Your function should have the form walk2D[n ] := NestWhileList[???,{0,0}, ???] For instance, walk2D[3] might out put {{0, 0}, {0.4535, −0.023}, {0.727, −1.154}, {2.78, −1.35}}. (6) Write a function addColor[myList ] that takes as input a list of points {x1, x2, . . . , xm} and as output returns the list {{Hue[1/m],Point[x1]},{Hue[2/m],Point[x2]}, ...,{Hue[m/m],Point[xm]}} where m is the length of myList). (7) Make a length 20 list called walkList as follows: walkList = Table[walk2D[100],{20}] In other words, this contains 20 different copies of walk2D[100]. (8) Define meanLength that is equal to the mean length of the 20 walks in walkList and define medianLength that is equal to the median length of the 20 walks in walkList. Express them as decimals using N. (9) Use Graphics and Manipulate Manipulate[Graphics[addColor[walkList[[i]]],Axes − > True], { i,1,20,1}] to display the 20 different walks in walkList. We will create some graphics that illustrate how quickly Newton’s method and bisection method will converge to the Pi by computing the root of Sin[x]. (a) Write a function newDisk[a ,b ] that takes as input two numbers a and b and as output returns the unique Disk that has diameter the line segment joining {a,0} and {b,0}. Your function should work both a < b and also if a > b. (b) Define f[x ] to be Sin[x] (c) Use the bisect method NestList (we will define this during class Wednesday) to make a length 5 list of intervals called bisectList = {{a1,b1},{a2,b2},{a3,b3},{a4,b4},{a5,b5}} starting with interval {4,2}. For example, if we were using the function x2 − 2 and starting interval [0,2], the bisectList would be {{0,2},{1,2},{1,1.5},{1.25,1.5}{1.375,1.5}} Be sure to make bisectList using NestList, not by typing the intervals out explicitly. ALso, be sure to make a length 5 list. If you use NestList[???,???,5] you will make a length 6 list. (d) Continue to let bisectList = {{a1,b1},{a2,b2},{a3,b3},{a4,b4},{a5,b5}}. Use Table to make a list called graphicBisectList = {{Hue[1/5],newDisk[a1,b1]},...,{Hue[5/5],newDisk[a5,b5]}} 1 2 SUMMER 2019 (e) (f) (g) (h) (i) (Your method should work just as easily if you have a length 100 list instead of a length 5 list. Don’t type out all 5 terms. Also don’t write the number 5. Instead use Length[bisectList]). These disks show how big our intervals are. Evaluate Show[Graphics[graphicBisectList],Plot[Sin[x],{x,2,4}],Axes − > True] Use NestList and Newton’s method to make a length 5 list newtonList = {x1,x2,x3,x4,x5} of approximations to a root of Sin[x] starting with x1=2. For example, if we were using the function x2 − 2 and we started with x1=2, our list would be {2, 1.5, 1.41667, 1.41422, 1.41421}. Continue to let newtonList = {x1,x2,x3,x4,x5}. Use Table to make a list called graphicNewtonList = {{ Hue[1/5],newDisk[x1,Pi]},..,{Hue[5/5],newDisk[x5,Pi]}} Evaluate Show[Graphics[graphicNewtonList],Plot[Sin[x],{x,2,4}],Axes − > True] How many disks do you clearly see in this image? Evaluate the same command again, this time using PlotRange to zoom in enough that you can see the smallest disk clearly. ...
Purchase answer to see full attachment
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

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 = TableHuei  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"]
m = Length[myList];
TableHuei  m, Point[myList[[i]]], {i, 1, m}

Print["Example with the list {{2,0},{2,1}}"]
Item 6
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 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"]

wbetrnes92 (455)
University of Virginia
Review
Review

Anonymous
Super useful! Studypool never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4