MTH 420-520 LAB 1

In this lab you will explore MATLAB tools useful for linear algebra and minimization of quadratic functionals.

Identify yourself as group "alpha" (MATLAB first timers) or "mu" (MATLAB intermediate) or "omega" (MATLAB experts),

Group alpha turns in solutions to [A,B,F].
Group mu turns in solutions to [B,C,F]
Group omega turns in solutions to [B, one (or all) of C-E,F]

Turning in your work is mandatory. Make sure all the steps are labelled properly and described well. A bunch of graphs stapled together does not constitute a solution worthy of credit.


Instructions follow below. Please note approximate timing of the steps and demonstrations. Groups alpha and mu should follow demonstrations.
Set-up phase: (14:00-14:05)
  1. Log in to the computer using your ONID account. Start the computer in Windows mode.

    I will be presenting in Windows so if you prefer to use MAC, try to follow what I am doing but I won't be able to assist you.

  2. Locate the basic tools:
    1. Locate a browser (Firefox or Chrome) and locate class website.
    2. Find MATLAB: as icon on desktop or in Start->Programs (Search for Matlab)

Laerning the syntax of MATLAB: DEMONSTRATION 14:05-14:20
  1. Learn the syntax of matrices and vectors in MATLAB by doing (or watch my demonstration). Some statements below have errors in them. Follow my demo and learn how to recover.
    A = [3 1; 2, 5]
    A (:,1)
    A(1,:)
    A(2,:)
    u = [2 1]
    u = [3,1];
    b = [pi,1]'
    A*u,A*b
    triu(A),tril(A)
    eig(A)
    [v,e]=eig(A)
    [l,u]=lu(A)
    A \ u
    x = A \ b
    A*x
    A*x == b
    A*x-b
    norm(A*x-b)
  2. Plotting in MATLAB
    x = linspace(0,pi),size(x)
    plot(x,x^2)
    plot(x,x.^2,'r*-',x,sin(x),'k-'); legend('quadratic','sine');
  3. Plotting in 2D.
    xy = linspace(-2,2);[XX,YY]=meshgrid(xy,xy);
    E = @(x,y)(x.^2+10*y.^2);
    surfc(XX,YY,E(XX,YY));
    contour(XX,YY,E(XX,YY));

Exploring positive definite systems and quadratic functions
  1. Plot the contours and the surface plot for the function phi(x)=xT K x when K=[2 -1; -1 2] as discussed in class. Identify that the origin is indeed the point where the function has a minimum.
  2. Let the forces be f1=1;f2=-1, with spring constants c1=pi, doubling from each spring to the next. Calculate the energy function E(x) as defined in class, when K=ATCA. Get the surface and contour plots for E(x). What is the equilibrium solution ? Identify it from the surface/contour plots and by solving the appropriate linear system. What kind of forces might correspond to this system ? Discuss.
    Now assume that the length of the springs (uncompressed and unstreteched) are proportional to the spring constants, with the length of the first being 1[m]. Draw a cartoon of the solution with masses and springs.
    Repeat the above when the forces are gravitational fi=mig, and the masses are m1=10;m2=1. Assume g=10.

Exploring LDLT decomposition of positive definite systems
  1. How do you find the LDLT decomposition of a matrix with MATLAB ? Use A=[20 4; 4 11] in your experiments (see Text 1.3)
  2. Solve problem 1.3.8 by experimenting. Use eig,lu,tril,triu appropriately to confirm positive definiteness.
  3. Same, but for 1.3.7.
  4. Solve (by hand calculation)
    • (520): 1.3.1, 1.3.5, 1.4.1, 1.4.11
    • (420): 1.3.1, 1.4.1

Extra credit: in (A-B), you solved the equilibrium problem. In class we discussed a dynamical problem mx''+kx=0 for a single mass-spring system. Write down the analogous problem for the system of masses with the matrix K, and solve it. (You have to assume some initial conditions, of course). Your solution can be numerical or by hand, if you are up for it. (Ask me how to get started if you are interested). Derive some cool graphics to show how the masses bounce back and forth.

To get my attention, please raise your hand.