Sept 15, recitation 2-3PM

addRandomStep[list_] := Append[list,Last[list]+ RandomReal[{-1,1},{2}]]

theWalk = {{0,0}}

theWalk = addRandomStep[theWalk]

theWalk = addRandomStep[theWalk]

For[i=1,i≤ 100, i++, theWalk= addRandomStep[theWalk]]

theWalk

ListLinePlot[theWalk]

Random walk in three 2

addRandomStep[list_] := Append[list,Last[list]+ RandomReal[{-1,1},{3}]]

theWalk = {{0,0,0}}

theWalk = addRandomStep[theWalk]

theWalk = addRandomStep[theWalk]

For[i=1,i≤ 100, i++, theWalk= addRandomStep[theWalk]]

theWalk

ListPointPlot3D[theWalk ]

Rolling my own graphics

spheres = Graphics3D[Table[Sphere[theWalk[[i]],0.2],{i,1,Length[theWalk]}]]

lines =Graphics3D[Table[Line[{theWalk[[i]],theWalk[[i+1]]}],{i,1,Length[theWalk]-1}]]

Show[lines,spheres]

Manipulate[
lines =Graphics3D[Table[Line[{theWalk[[i]],theWalk[[i+1]]}],{i,1,last-1}]];
spheres = Graphics3D[Table[Sphere[theWalk[[i]],0.2],{i,1,last}]];
test= Graphics3D[Table[Text[i,theWalk[[i]]],{i,1,last}]];
Show[lines,spheres,test],
{last,1,Length[theWalk]}]

Making a random three dimensional vector of magnitude 10

ranVec[nDum_, range_, mag_] :=
Module[
{myvector,currentmag},
myvector= RandomReal[range {-1,1},{nDum}];
currentmag = Sqrt[myvector.myvector];
mag myvector/currentmag
]

ranVec[4,1,10]

Numerical solutions

Solve[a x^3 + b x^2 + c  x + d==0,x]

quintic = Sum[RandomReal[] x^i,{i,1,5}]

Solve[quintic,x]

NSolve[quintic==0,x]

squintic = e x^4 + f x^5+a x^3 + b x^2 + c  x + d==0

thesols = Solve[squintic,x]

asols =thesols/.{a->1, b-> 2, c-> 7, d-> 4, e-> Pi, f-> 2}

N[asols]

Numerical solutions to differential equations

lhs = D[y[x],{x,2}] y[x] + 1/(1+x^2)

rhs = 0

DSolve[lhs==rhs,y[x], x]

NDSolve[{lhs==rhs, y[0]== 1,y'[0]== 0},y[x], {x,0,10}]

ysol = y[x]/.NDSolve[{lhs==rhs, y[0]== 1,y'[0]== 0},y[x], {x,0,1.429606059491323`}]

{InterpolatingFunction[{{0.`,1.`}},"<>"][x]}

Plot[ysol,{x,0,1.4}]

NDSolve[{lhs==rhs, y[2]== 1,y'[2]== 0},y[x], {x,2,10}]

ysol = y[x]/.NDSolve[{lhs==rhs, y[0]== 1,y'[0]== 0},y[x], {x,0,6.1537186255136955`}]

{InterpolatingFunction[{{0.`,1.`}},"<>"][x]}

Plot[ysol,{x,2,6.1537186255136955`}]