% 16.01 / 16.02 Unified Engineering, Fall 2006 % Introduction to MATLAB: Matrix Computations % Instructor: Violeta Ivanova, MIT Academic Computing, violeta@mit.edu % EXERCISE 2 System of Linear Equations % MATLAB vectors, matrices, matrix operations, curve fitting, eigenvalues, plotting. % The coordinates (x1,y1), (x2,y2), (x3,y3) and (x4,y4) of four points are % given: (1, 54), (5, 82), (8, 40), and (10, 10). % Find a cubic equation y(x) that passes through the four points i.e.: % y = c1*x^3 + c2*x^2 + c3*x + c4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % A. SOLVE A SYSTEM OF LINEAR EQUATIONS FOR C1, C2, C3, AND C4. % A1. Define column vectors X and Y from the points' coordinates % X = (x1, x2, x3, x4) and Y = (y1, y2, y3, y4) % A2. Define matrix A from X % If C = (c1, c2, c3, c4) is the vector we want to solve for, % we need to define a matrix from the vector X, so that Y = AC. % Hint: use the .^ operator and function ONES to simplify the code. % A3. Solve Y = AC for C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % B. COMPUTE A QUADRATIC AND A STRAIGHT LINE FIT TO THE POINTS % Hint: use function POLYFIT % B1. Quadratic fit % B2 Straight line fit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % C. PLOT THE CUBIC, QUADRATIC, STRAIGHT LINE AND POINTS % C1. Compute a cubic curve, a quadratic curve, and a straight line for an % interval of x from 0 to 10. % Hint: use built-in function POLYVAL % C2. Plot the cubic curve, quadratic curve, straight line, and points on % on the same figure. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % D. EIGENVVALUES AND EIGENVECTORS % An eigenvalue and eingenvector of a square matrix A are a scalar lambda % and a nonzero vector V such that A*lambda = A*V. % D1. Compute the eigenvalues and eigenvectors of A % Hint: use built-in function EIG. % D2. Check solution (optional)