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 where
,
, and x and y range from -pi to pi. Label the axes.
12. Produce a contour plot of
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 of
probabilities
that you'll end up at website
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
to convert between the two.
18. How would you graph the function , in a way that highlights
this functional relationship? I.e. given vectors
and
satisfying
, what Matlab command should you use to plot
versus
?
19. How would you graph the function , 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
returns the output vector
22. Convert the following 2nd order ODE to a 1st order system of ODE in two variables.
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
where ,
represents the vertical position, and
represents the vertical velocity. Represent the two free variables
with the vector
and reexpress the two equations above as
an ODE system of the form
Note that both sides of this equation are vectors: and
. Your job is to find the functions
and
.
Write an anonymous function in Matlab that computes for an input vector
,
and then use ode45 to integrate this system from
to
from the initial conditions
.
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 is defined by
for each component of the M dimensional vector
. 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.