%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Solution to homework 1 of CS 525 (Linear Programming with Matlab) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Please follow the instruction on % "http://pages.cs.wisc.edu/~swright/525/MATLAB.setup" to set up your % computer if you use the computer in CS. If not, you can download the data % file "hwk1.mat" on the course website % "http://www.cs.wisc.edu/%7Eswright/525/homeworks/hwk1.mat". Please make % sure the data file stays in the same folder as your ".m" file or add the % path of the folder containing the data file by writing % "addpath('thefolderpath');" at the beginning of your code. % clean the command window clc; % if you do not use the CS computer or do not copy the data file to the % current folder, then run the next line % addpath('thefolderpath'); % create a new diary or open an existing diary file diary hwk1.Liu.Ji; % clear all variable in the workspace clear all; % load the data file "hwk1.mat" load hwk1; % list the names of all variables currently in workspace who; % calculate F = AB without display. note that ";" can prevent printing the % result. one can print the result by removing ";" F = A*B; % calculate and print A-2alphaC A - 2*alpha*C % print out F. one can also use disp(F) to print the result. the difference % is that disp(F) would not print the name of this variable. F % "./" a very useful operator. "A ./ B" denotes element-by-element % division. A and B can be vectors, matrices, or tensors. of course, one % should make sure the size of A is equal to that of B. v = 2*x ./ y % change the 5th component of x into -8 v(5) = -8; % reorder the entries in x and save it to w w = x([6, 2, 4, 1, 3, 5])' % find the minimal entry of x min(x) % calculate D = C'A + 2B D = C'*A + 2*B; % lu decomposition. one also can use [L, U, P] = lu(D). in that case, D = % inv(P)*L*U [L, U] = lu(D); % max(A) serves to find the maximal value in each column if A is a matrix. If A is % a vector (no matter a row or column), max(A) returns the maximal entry. % max(A(:)) is another way to get the maximal entry in the matrice A, where A(:) % vectorized the matrix A. max(max(abs(L*U - D))) % extract the diagonal of the matrix U into d (d is a vector) d = diag(D) % set the format of numeric values displayed in the command window format long; sum(d) % recover the default setting format short; % close the diary diary off;