User Tools

Site Tools


1. Produce a plot of sin(x) versus x in blue and cos(x) versus x in red for 100 evenly spaced points between 0 and 2pi. Label the axes.

2. Given matrix A, set v to the jth column of A.

3. Given matrix A, set v to the ith row of A.

4. Suppose matrix A has M rows and N cols. Set B to A with its columns in reversed order.

5. Solve the system of equations

  2y - x  = 1 
  3y + 2z = 5 
  -3x + z = -2

6. Produce a vector of 100 random floating-point numbers between 0 and 10.

7. Produce a vector of 100 random integers between 0 and 10.

8. Produce a random permutation of the integers between 1 and 10.

9. Produce a random permutation of the vector v = [3 3 4 5 7];

10. Produce all permutations of the vector v = [3 3 4 5 7];

11. Produce a quiver plot of the vector field $v = [v_x, v_y]$ where $v_x = \sin(x) \cos(y)$, $v_y = x y$, and x and y range from -pi to pi. Label the axes.

12. Produce a contour plot of $f(x,y) = \sin(x^2+y^2)/\sqrt{x^2 + y^2}$ where x and y range from -10 to 10. Label the axes.

13. Produce a 3d surface plot of the function from problem 12 over the same range, and with a color bar. Label the axes.

14. Write down the connectivity matrix C for the links in this small network of websites.

15. Write Matlab code that converts the connectivity matrix C to a transition matrix T that governs the transition of probabilities under random surfing.

16. Given T, write Matlab code that computes the vector $x$ of probabilities $x_j$ that you'll end up at website $j$ after a long night of random websurfing.

17. Write an equation for y as a function of x for the following data plot. Bonus: express exponential functions as powers of e rather than powers of 10. Use $e^{2.3}\approx 10$ to convert between the two.

18. How would you graph the function $y(x) = x^c$, in a way that highlights this functional relationship? I.e. given vectors $x$ and $y$ satisfying $y_i = x_i^c$, what Matlab command should you use to plot $y$ versus $x$?

19. How would you graph the function $y(x) = c^x$, in a way that highlights this functional relationship?

20. Write an anonymous function that returns the square of its input.

21. Write an anonymous function that, for an input vector $x = [x_1, ~x_2]$ returns the output vector $f(x) = [4 x_1 x_2, ~\sin(x_1) \cos(x_2)]$

22. Convert the following 2nd order ODE to a 1st order system of ODE in two variables.

$dx^2/dt^2 + 3\; dx/dt + \sin(x) = 0$

22. Show how to integrate the system of ODEs from problem 22 from t = 0 to 10 using the initial condition x(0) = 0, dx/dt(0) = 1. Write the ODE system in Matlab using an anonymous function.

23. Compute the terminal velocity of a ping-pong ball dropped from a great height, using this system of equations

 dy/dt = v_y

 d v_y/dt = -g - \mu v_y |v_y|

where $g = 9.81, ~\mu =0.35$, $y$ represents the vertical position, and $v_y$ represents the vertical velocity. Represent the two free variables with the vector $x = [y, ~v_y]$ and reexpress the two equations above as an ODE system of the form

$dx/dt = f(x)$

Note that both sides of this equation are vectors: $dx/dt = [dx_1/dt, ~dx_2/dt]$ and $f(x) = [f_1(x_1, x_2), ~f_2(x_1, x_2)]$. Your job is to find the functions $f_1$ and $f_2$.

Write an anonymous function in Matlab that computes $dx/dt = f(x)$ for an input vector $x$, and then use ode45 to integrate this system from $t=0$ to $t=100$ from the initial conditions $x(0) = [y(0), ~v_y(0)] = [0, 0]$.

24. Plot the position of the ping-pong ball as a function of time. Label the axes.

25. Write a function that performs matrix-vector multiplication for a sparse matrix A, that accesses only nonzero elements of A.

For an M x N matrix A and an N-dimensional vector x, the matrix-vector product $y = Ax$ is defined by

y_i = \sum_{j=1}^N A_{ij} x_j

for each component $y_i$ of the M dimensional vector $y$. But don't code that formula directly! Instead start your function with

  K = nnz(A);
  [i,j,a] = find(A);

and write the matrix-vector multiplication as a loop over the K nonzero elements of A.

gibson/teaching/fall-2012/math445/pf1.txt · Last modified: 2012/12/05 13:23 by gibson