Contents

Aaron Klapheck

Assignment #2

clear, clc

Problem 1.b,c

x = [2:0.2:14]              % b. method 1
a = length(x)               % find number of elements for method 2.
x = linspace(2, 14, a)      % b. method 2

x = linspace(-2, 5, 50)     % c. method 1
a = abs(x(1)-x(2))          % find incriment for method 2.
x = [-2:a:5]                % c. method 2
x =

  Columns 1 through 9 

    2.0000    2.2000    2.4000    2.6000    2.8000    3.0000    3.2000    3.4000    3.6000

  Columns 10 through 18 

    3.8000    4.0000    4.2000    4.4000    4.6000    4.8000    5.0000    5.2000    5.4000

  Columns 19 through 27 

    5.6000    5.8000    6.0000    6.2000    6.4000    6.6000    6.8000    7.0000    7.2000

  Columns 28 through 36 

    7.4000    7.6000    7.8000    8.0000    8.2000    8.4000    8.6000    8.8000    9.0000

  Columns 37 through 45 

    9.2000    9.4000    9.6000    9.8000   10.0000   10.2000   10.4000   10.6000   10.8000

  Columns 46 through 54 

   11.0000   11.2000   11.4000   11.6000   11.8000   12.0000   12.2000   12.4000   12.6000

  Columns 55 through 61 

   12.8000   13.0000   13.2000   13.4000   13.6000   13.8000   14.0000


a =

    61


x =

  Columns 1 through 9 

    2.0000    2.2000    2.4000    2.6000    2.8000    3.0000    3.2000    3.4000    3.6000

  Columns 10 through 18 

    3.8000    4.0000    4.2000    4.4000    4.6000    4.8000    5.0000    5.2000    5.4000

  Columns 19 through 27 

    5.6000    5.8000    6.0000    6.2000    6.4000    6.6000    6.8000    7.0000    7.2000

  Columns 28 through 36 

    7.4000    7.6000    7.8000    8.0000    8.2000    8.4000    8.6000    8.8000    9.0000

  Columns 37 through 45 

    9.2000    9.4000    9.6000    9.8000   10.0000   10.2000   10.4000   10.6000   10.8000

  Columns 46 through 54 

   11.0000   11.2000   11.4000   11.6000   11.8000   12.0000   12.2000   12.4000   12.6000

  Columns 55 through 61 

   12.8000   13.0000   13.2000   13.4000   13.6000   13.8000   14.0000


x =

  Columns 1 through 9 

   -2.0000   -1.8571   -1.7143   -1.5714   -1.4286   -1.2857   -1.1429   -1.0000   -0.8571

  Columns 10 through 18 

   -0.7143   -0.5714   -0.4286   -0.2857   -0.1429         0    0.1429    0.2857    0.4286

  Columns 19 through 27 

    0.5714    0.7143    0.8571    1.0000    1.1429    1.2857    1.4286    1.5714    1.7143

  Columns 28 through 36 

    1.8571    2.0000    2.1429    2.2857    2.4286    2.5714    2.7143    2.8571    3.0000

  Columns 37 through 45 

    3.1429    3.2857    3.4286    3.5714    3.7143    3.8571    4.0000    4.1429    4.2857

  Columns 46 through 50 

    4.4286    4.5714    4.7143    4.8571    5.0000


a =

    0.1429


x =

  Columns 1 through 9 

   -2.0000   -1.8571   -1.7143   -1.5714   -1.4286   -1.2857   -1.1429   -1.0000   -0.8571

  Columns 10 through 18 

   -0.7143   -0.5714   -0.4286   -0.2857   -0.1429   -0.0000    0.1429    0.2857    0.4286

  Columns 19 through 27 

    0.5714    0.7143    0.8571    1.0000    1.1429    1.2857    1.4286    1.5714    1.7143

  Columns 28 through 36 

    1.8571    2.0000    2.1429    2.2857    2.4286    2.5714    2.7143    2.8571    3.0000

  Columns 37 through 45 

    3.1429    3.2857    3.4286    3.5714    3.7143    3.8571    4.0000    4.1429    4.2857

  Columns 46 through 50 

    4.4286    4.5714    4.7143    4.8571    5.0000

Problem 2.b

x = logspace(1, 3, 50)
x =

  1.0e+003 *

  Columns 1 through 9 

    0.0100    0.0110    0.0121    0.0133    0.0146    0.0160    0.0176    0.0193    0.0212

  Columns 10 through 18 

    0.0233    0.0256    0.0281    0.0309    0.0339    0.0373    0.0409    0.0450    0.0494

  Columns 19 through 27 

    0.0543    0.0596    0.0655    0.0720    0.0791    0.0869    0.0954    0.1048    0.1151

  Columns 28 through 36 

    0.1265    0.1389    0.1526    0.1677    0.1842    0.2024    0.2223    0.2442    0.2683

  Columns 37 through 45 

    0.2947    0.3237    0.3556    0.3907    0.4292    0.4715    0.5179    0.5690    0.6251

  Columns 46 through 50 

    0.6866    0.7543    0.8286    0.9103    1.0000

Problem 3

x = linspace(0, 10, 6)
A = [3*x;5*x-20]
x =

     0     2     4     6     8    10


A =

     0     6    12    18    24    30
   -20   -10     0    10    20    30

Problem 5

A = [3, 7, -4, 12; -5, 9, 10, 2; 6, 13, 8, 11; 15, 5, 4, 1]
v = A(:, 2)             % a.
w = A(2, :)             % b.
A =

     3     7    -4    12
    -5     9    10     2
     6    13     8    11
    15     5     4     1


v =

     7
     9
    13
     5


w =

    -5     9    10     2

Problem 6.b,c

C = A(2:4, :)           % b. uses A from problem 5.
D = A(1:2, 2:4)         % c.
C =

    -5     9    10     2
     6    13     8    11
    15     5     4     1


D =

     7    -4    12
     9    10     2

Problem 8

max(A(:, 1))            % Max value for column 1 of A
max(A(:, 2))            % Max value for column 2 of A
max(A(:, 3))            % Max value for column 3 of A
max(A(:, 4))            % Max value for column 4 of A

min(A(:, 1))            % Min value for column 1 of A
min(A(:, 2))            % Min value for column 2 of A
min(A(:, 3))            % Min value for column 3 of A
min(A(:, 4))            % Min value for column 4 of A

x = A'

max(x(:, 1))            % Max value for row 1 of A
max(x(:, 2))            % Max value for row 2 of A
max(x(:, 3))            % Max value for row 3 of A
max(x(:, 4))            % Max value for row 4 of A

min(x(:, 1))            % Min value for row 1 of A
min(x(:, 2))            % Min value for row 2 of A
min(x(:, 3))            % Min value for row 3 of A
min(x(:, 4))            % Min value for row 4 of A
ans =

    15


ans =

    13


ans =

    10


ans =

    12


ans =

    -5


ans =

     5


ans =

    -4


ans =

     1


x =

     3    -5     6    15
     7     9    13     5
    -4    10     8     4
    12     2    11     1


ans =

    12


ans =

    10


ans =

    13


ans =

    15


ans =

    -4


ans =

    -5


ans =

     6


ans =

     1