User Tools

Site Tools


matlab:asciunqoc

This is an old revision of the document!


MATLAB exercise solutions

Century College CSCI 1081 Spring 2016

ex1.m
a = [1 2 3 4 5 6];
%a = [1:6]; % also works
 
disp(a * 7);
ex2.m
% not provided, but it's solvable!
ex3a.m
a = [2,  3,  1,  5; 1,  0,  3,  1,; 0,  2, -3,  2; 0,  2,  3,  1,];
% either works for multiplying a matrix with a scalar:
disp(a * 7);
disp(a .* 7);
ex3b.m
a = [2,  3,  1,  5; 1,  0,  3,  1,; 0,  2, -3,  2; 0,  2,  3,  1,];
b = inv(a);
disp(a * b); % result is (approx.) identity matrix
ex3c.m
a = [2,  3,  1,  5; 1,  0,  3,  1,; 0,  2, -3,  2; 0,  2,  3,  1,];
b = [ 1,2,3; 10,20,30;.1,.2,.3];
matrixinfo(a);
matrixinfo(b); % square matrix of Inf values
matrixinfo.m
function matrixinfo(m)
% matrix_info(m)
% Tell the user whether mtx is a square matrix. If it is a square matrix, 
% tell the user the matrix's transpose, whether the matrix is invertible, 
% and if it is invertible what the inverse matrix is.
 
msize = size(m);
if ndims(m) == 2 && msize(1) == msize(2),
    disp('It''s a square matrix.');
    disp('The transpose is:');
    disp(m');
    disp('The inverse is:');
    disp(inv(m));
else
    disp('The matrix isn''t square.');
end % if
end % function
ex.m
 
matlab/asciunqoc.1462147740.txt.gz · Last modified: 2016/05/02 00:09 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki