Excercise 2

Plotting

Simple plots

Plot the following functions
1. sin(x)
2. cos(x)
3. (e^x)
4. Random[]
4. sin(cos(x)) and (e^(sin(x)))in the same figure.
5. (Subscript[J, 0])(x),  (Subscript[J, 1])(x),  (Subscript[J, 2])(x), and (Subscript[J, 3])(x) where (Subscript[J, n])(x)is the Bessel function of order n, given in Mathematica by the function BesselJ[n,x].
6. Try plotting the factorial function, n!.

Parametric plots

1. Plot the curve x(t)  =  (t^2) + 10  t + 1,  
      y(t) = (1/((t^2) + 10))in x,  y -coordinates.

2. Plot the curve (x(t),  y(t))  =  (cos(2 t), 
          sin(π t))in x, y -coordinates.

3*. Plot the function z = (e^(i t)),  
      0  <  t  <  2  π on the complex z-plane, that is, in (Re z,  Im z) coordinates. The functions Re[...] and Im[...] give the real and imaginary parts of a variable

3D and contour plots

1. Use Plot3D[...] and ContourPlot[...] to plot the following functions:
	a. (1/((x^2) + (y^2))), -5 < x < 5,  -5 < y < 5
	
	b. sin(x)cos(y)

Plot options

1. Using Mathematicas help system, find out how you can make coloured plots. Try it by plotting sin(x) and cos(x) to same figure with different colours. Can you also find a way to change the thickness of the lines?

2. Plot cos(2000 sin(x)), where 0 < x < π. Find out how you can increase the number of points used in the plot to produce a better plot.

Additional excersises

1. Mathematica knows many special functions. Try plotting some of the following:
	LegendreP[n,x], try with some integer values of n.
	HermiteH[n,x]
	LaguerreL[n,x]
	MathieuC[a,q,x], try for example  a = 3,  q = 2
	Zeta[s,a]
If you're interested, you can use the Mathematica help system to get more information about these functions.

2. Parametric 3D plot. Surfaces in three dimensions can be plotted by parametrizing the surface with two variables. As an example, try plotting the Möbius strip, given by the equations
	x(t, s)  =  [R + s cos((1/2) t)] 
          cos t
y(t, s) =  [R + s cos((1/2) t)] 
          sin t
z(t, s)  =  s sin((1/2) t),	0 ≤ t < 2  π,  -w ≤ 
        s < w,
where R is the radius of the strip and w its width. Use Mathematicas built-in function ParametricPlot3D[{x, y, z}, {s, (Subscript[s, start]),  (Subscript[s, end])}, {t, (Subscript[t, start]),(Subscript[t, end])}], where x,  y,  and z are the coordinates and s and t are the parameters. Try different values of R and w.

Defining functions

1. Define the function f(x) = cos(10 sin(x))and plot it over t ∈  [0, 2  π]
2. Define the function a(x, y) that calculates the average of two numbers x and y.
3. Define functions f(x) = (x^2), g(x) = exp(-x) and h(x)  =  g(f(x)). Plot the function over -5 < t < 5.
4. Define a function that computes (e^(-((x^2) + (y^2)))) and plot it as a three dimensional plot.
5. Test the difference between delayed and direct assignment.
	i. Set a = 1
	ii. Define the function f1(x) = exp(a x) using direct assignment ('=' operator)
	iii. Define the function f2(x) = exp(a x) using delayed assignment (':=' operator)
	iv. Plot f1(x) and f2(x) for 0 < x < 2.
	v. Set a = 1/2
	vi. Plot f1(x) and f2(x) for 0 < x < 2.

Equations

Polynomial equations

1. Solve the following sets of equations symbolically, and find the numerical values of the solutions:
a.	(x^3) + x + 1 = 0

b. 	(x^2) + (y^2) = 1, 
y = 
        2  x + 1

2. Use Eliminate[...] to eliminate the variable z from the following set of equations
	x + y + z = 0
x y z =  1
(x/z) = 2

2. Use the function Reduce[...] to find the roots of the following equations:
a.	(x^3) + p (x^2) + q (x^2) + r = 0

b.	x y  =  -2
x + y = 1

c.	x y  =  -2
x + y = 1
x  >  0

d.	(x^3) - a (x^2) + x - a = 0
x > 0

3. Find the general solution of a (x^4) +  b (x^3) + c (x^2) + d x + e = 0. The result be really complicated!

4. Find the general solution of (x^2) + p x + 1 = 0 and plot the first solution as a function of p.

5*. Find the general solution of (x^2) + p x + q = 0, make a function f(p, q) that gives the first solution, and finally plot the function as a three dimensional plot, for -15 < p < 15,  -15 < q < 15.

6*. Try what SolveAlways[...] does. Use it like Solve[...] on the second order polynomial equation a (x^2) + b x + c = 0.

Algebraic equations

1. Use Solve[...] to find the solutions to the following equations
a.	(e^x) = 2

b	(Sqrt[(x^2) - 1]) = (1/2)

c.	(x^y) = 1
x + y = 2

d.	x (e^x) = 1

e.	x exp(exp(x))  =  1

2. Use Reduce[...] to find the solutions to the following equations
a.	((sin(x))^2) + cos(x) = 0

b.	(e^(2  x)) + 2  (e^x) - 
          3 = 0

3. Find the roots of the following equations. To get an initial guess for the solution, plot the right- and left-hand sides of the equations (or right-hand side minus the left-hand side alone) and make an estimate for the position of the root.
a.	cos(x)  =  x

b.	ln x = 1/(x^2)

c.	(Subscript[J, 0])(x) = 0,  5 < x < 6 
	(Subscript[J, 0])(x)is the Bessel J function, BesselJ[0,x] in Mathematica.
	
d. 	Define the function g(x) =  exp(x sin(x)) - x, plot it, and find its root.

Linear equations

Solve the following linear equations:
a.	(Subscript[x, 1]) + (Subscript[x, 2]) = 1
(Subscript[x, 1]) - (Subscript[x, 2]) = -1

b.	(Subscript[x, 1]) + 2  (Subscript[x, 2]) + 10  (Subscript[x, 3]) = 
        10, 
10  (Subscript[x, 1]) + 2  (Subscript[x, 2]) + 10  (Subscript[x, 3]) = 
        1, 
(Subscript[x, 1]) + 2  (Subscript[x, 2]) + 3  (Subscript[x, 3]) = 0

c.	(({{1, 2, 3}, {0, 1, 2}, {0, 0, 1}}))(({{(Subscript[x, 1])}, {(Subscript[x, 2])}, {(Subscript[x, 3])}}))=(({{1}, {1}, {1}}))

d.	(({{1, 1, 1}, {1, 0, -1}, {2, 1, 0}}))(({{(Subscript[y, 1])}, {(Subscript[y, 2])}, {(Subscript[y, 3])}}))=(({{0}, {1}, {2}}))

Misc. equations

Solve the following equations. Choose an appropriate function (Solve, NSolve, FindRoot, LinearSolve) 
a.	a b  +  c = 0
c + a = 1
a b c = 1, 	a,  b,  c  =  ?

b.	s + 2  t + 3  u = 10
t + u = 1
u - t = 0,	s,  t,  u  =  ?

c.	x log(x) = 10, 	x = ?

d.	sin(2  x) + 3 cos(x) + 1 = 0,	x = ?

Interpolation

Tables

1. Make a table called DataA, that has as its elements ((Subscript[x, i]),  (Subscript[y, i])) the following table
	(Subscript[x, i])	(Subscript[y, i])
	1	4.0
	3	2.8
	4	2.5
	5	3.2
	6	3.9
	10	5.0
	
2. Make a table called DataB that has as its elements ((Subscript[x, i]),  ((Subscript[x, i])^2) + 10 (Subscript[x, i]) + 1), where (Subscript[x, i]) = 0, 1, 2,  ... 

3. Plot the tables DataA and DataB

Interpolating functions

1. Make a table that has as its elements ((Subscript[x, i]),  (Subscript[x, i]) exp(-(Subscript[x, i]))), where (Subscript[x, i]) = 0, 1/2, 1, 3/2.  ..  Assign the symbol A to the table (A=Table[...])

2. Print out the contents of table A using the TableForm[...] function.

3. Make an interpolating polynomial to table A. 

4. Plot the interpolating function.

5. Make an spline interpolating function to table A.

6. Plot the spline function.