(* You should be able to copy and paste this text file directly into Mathematica. These notes will be interpreted as commented code. *) (* Lazy implementation of Newton's method *) f[x_] := x^3 - 2x - 2 nif[x_] := x - f[x] / f'[x] (* This computes the Newton iterating function nif[x] for the given function f[x]. Changing the definition of f[x] above and rerunning both lines of code will automatically change nif[x] *) NestList[nif, 1.5`20, 10] (* This computes the first ten iterates of the Newton iterating function applied to 1.5, where 1.5 starts with 20 decimal places of precision. *) (* Note that the quote mark is the angle quote `, which on most keyboards is to the left of the 1 key, above the Tab key. The notation a`b tells Mathematica that the number a is given to b digits of precision. *) (* Mathematica's internal system will keep track of precision losses during computations and display fewer digits accordingly -- exceedingly useful in numerical computation. *) (* For problem 4 *) Clear[a] (* This clears the definition of the variable a, in case it was previously defined to be something else. If you want to define the variable a again later, simply assign it a new value. *) p[x_] := x^3 - a x (* This defines the function p[x]. Note that you must include underscores after each variable in the function definition to tell Mathematica that x is one of the variables that p depends on. *) Simplify[ (p[p[x]] - x) / (p[x] - x)] (* This will simplify the quotient (p[p[x]] - x) / (p[x] - x), useful for finding 2-cycles *) (* For problem 7 *) p[x_]:= 1 + x - 3 x^2 - 15/4 x^3 + 3/2 x^4 + 9/4 x^5 (* This is the function in part b *) (* For problem 8 *) s1[x_]:= -x + x^2 - x^3 + 3/2 x^4 - 5/2 x^5 + 19/8 x^6 - 139/80 x^8 + 653/1000 x^10 s2[x_]:= -x + x^2 - x^3 + 3/2 x^4 - 5/2 x^5 + 19/8 x^6 - 139/80 x^8 + 652/1000 x^10 (* These are the two functions in the problem *) NestList[s1, 0.1`50, 10] (* This will compute the first 10 iterates of 0.1 under s1, where 0.1 starts with 50 decimal places of precision. *) Expand[s1[s1[x]]] (* This will expand out the expression s1[s1[x]] *) Series[s1[s1[x]], {x,0,14}] (* This will compute the Taylor series expansion for s1[s1[x]] in the variable x, centered at x=0, to degree 14 in x *) (* For problem 9 *) f[x_] := x + x Sin[1/x] NestList[f, 0.1`20, 10] (* This will compute the first 10 iterates of 0.1 under the function f, where 0.1 starts with 20 decimal places of precision. *) NestList[f, 0.00015494157427205179, 10] (* This will compute the first 10 iterates of 0.00015494157427205179 under the function f *)