matlab:asciunqoc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
matlab:asciunqoc [2016/05/02 00:09] – mithat | matlab:asciunqoc [2021/12/07 20:32] (current) – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== MATLAB exercise solutions ====== | + | ====== MATLAB exercise solutions |
- | Century College CSCI 1081 | + | |
- | Spring 2016 | + | |
<file matlab ex1.m> | <file matlab ex1.m> | ||
Line 11: | Line 9: | ||
<file matlab ex2.m> | <file matlab ex2.m> | ||
- | % not provided, but it's solvable! | + | % not provided. |
</ | </ | ||
<file matlab ex3a.m> | <file matlab ex3a.m> | ||
- | a = [2, | + | 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: | % either works for multiplying a matrix with a scalar: | ||
disp(a * 7); | disp(a * 7); | ||
Line 22: | Line 20: | ||
<file matlab ex3b.m> | <file matlab ex3b.m> | ||
- | a = [2, | + | a = [2 3 1 5; 1 0 3 1; 0 2 -3 2; 0 2 3 1]; |
b = inv(a); | b = inv(a); | ||
disp(a * b); % result is (approx.) identity matrix | disp(a * b); % result is (approx.) identity matrix | ||
Line 28: | Line 26: | ||
<file matlab ex3c.m> | <file matlab ex3c.m> | ||
- | a = [2, | + | 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]; | + | b = [1 2 3; 10 20 30; 0.1 0.2 0.3]; |
matrixinfo(a); | matrixinfo(a); | ||
matrixinfo(b); | matrixinfo(b); | ||
Line 38: | Line 36: | ||
% matrix_info(m) | % matrix_info(m) | ||
% Tell the user whether mtx is a square matrix. If it is a square matrix, | % Tell the user whether mtx is a square matrix. If it is a square matrix, | ||
- | % tell the user the matrix' | + | % display |
- | % and if it is invertible what the inverse | + | |
msize = size(m); | msize = size(m); | ||
Line 55: | Line 52: | ||
</ | </ | ||
- | <file matlab | + | <file matlab |
+ | % Input data for three monkeys | ||
+ | NUM_MONKEYS = 3; | ||
+ | NUM_DAYS = 5; | ||
+ | % initialize data to -1) | ||
+ | data = ones(NUM_MONKEYS, | ||
+ | |||
+ | % Get monkey data | ||
+ | for monkey = 1: | ||
+ | disp(' | ||
+ | % enter row data as days of week | ||
+ | for day = 1:NUM_DAYS, | ||
+ | is_valid = false; | ||
+ | while ~is_valid, | ||
+ | prompt = [' | ||
+ | data(monkey, | ||
+ | is_valid = data(monkey, | ||
+ | if ~is_valid, | ||
+ | disp(' | ||
+ | end; % if | ||
+ | end % while | ||
+ | end % inner for | ||
+ | end % outer for | ||
+ | |||
+ | % for each column, compute the average: | ||
+ | avgeaten = zeros(1, NUM_DAYS); | ||
+ | for day = 1:NUM_DAYS, | ||
+ | avgeaten(day) = mean(data(:, | ||
+ | end % for | ||
+ | |||
+ | % Display report | ||
+ | disp(' | ||
+ | disp(' | ||
+ | disp(avgeaten); | ||
+ | |||
+ | disp([' | ||
+ | disp([' | ||
+ | disp(' | ||
</ | </ |
matlab/asciunqoc.1462147740.txt.gz · Last modified: 2016/05/02 00:09 by mithat