Back to tutorial index

# Lab Solutions

## Introduction

function lab_solns()

set1()
set2()

end

Back to lab exercises.

Back to the top

## Set 1

function set1()
n = 100;
x = rand(1,n);   % array of 'n' random numbers between 0 and 1

Back to the top

## Exercise 1 - sum(x)

sum(x)
ans =

53.854796213711992



Back to the top

## Exercise 2 : min(x)

min(x)
ans =

0.001674528105046



Back to the top

## Exercise 3 : mean(x)

mean(x)
ans =

0.538547962137120



Back to the top

## Exercise 4 : length(x)

length(x)
ans =

100



Back to the top

## Exercise 5 : cumprod(x)

cumprod(x)
ans =

Columns 1 through 3

0.576134335746674   0.356323681788646   0.334802334680441

Columns 4 through 6

0.109403553149475   0.095792505648060   0.034944417483306

Columns 7 through 9

0.030390946156260   0.024269177025180   0.014090136450668

Columns 10 through 12

0.010687404472219   0.002953412834502   0.001388473741046

Columns 13 through 15

0.001188206561286   0.000001989685281   0.000001096300091

Columns 16 through 18

0.000000972110063   0.000000088186671   0.000000076908062

Columns 19 through 21

0.000000017270597   0.000000010189656   0.000000001588589

Columns 22 through 24

0.000000000148542   0.000000000016426   0.000000000009073

Columns 25 through 27

0.000000000007373   0.000000000002655   0.000000000001058

Columns 28 through 30

0.000000000000240   0.000000000000068   0.000000000000024

Columns 31 through 33

0.000000000000020   0.000000000000018   0.000000000000006

Columns 34 through 36

0.000000000000004   0.000000000000002   0.000000000000002

Columns 37 through 39

0.000000000000000   0.000000000000000   0.000000000000000

Columns 40 through 42

0.000000000000000   0.000000000000000   0.000000000000000

Columns 43 through 45

0.000000000000000   0.000000000000000   0.000000000000000

Columns 46 through 48

0.000000000000000   0.000000000000000   0.000000000000000

Columns 49 through 51

0.000000000000000   0.000000000000000   0.000000000000000

Columns 52 through 54

0.000000000000000   0.000000000000000   0.000000000000000

Columns 55 through 57

0.000000000000000   0.000000000000000   0.000000000000000

Columns 58 through 60

0.000000000000000   0.000000000000000   0.000000000000000

Columns 61 through 63

0.000000000000000   0.000000000000000   0.000000000000000

Columns 64 through 66

0.000000000000000   0.000000000000000   0.000000000000000

Columns 67 through 69

0.000000000000000   0.000000000000000   0.000000000000000

Columns 70 through 72

0.000000000000000   0.000000000000000   0.000000000000000

Columns 73 through 75

0.000000000000000   0.000000000000000   0.000000000000000

Columns 76 through 78

0.000000000000000   0.000000000000000   0.000000000000000

Columns 79 through 81

0.000000000000000   0.000000000000000   0.000000000000000

Columns 82 through 84

0.000000000000000   0.000000000000000   0.000000000000000

Columns 85 through 87

0.000000000000000   0.000000000000000   0.000000000000000

Columns 88 through 90

0.000000000000000   0.000000000000000   0.000000000000000

Columns 91 through 93

0.000000000000000   0.000000000000000   0.000000000000000

Columns 94 through 96

0.000000000000000   0.000000000000000   0.000000000000000

Columns 97 through 99

0.000000000000000   0.000000000000000   0.000000000000000

Column 100

0.000000000000000



Back to the top

## Exercise 6 : max(x)

max(x)
ans =

0.989629387448602



Back to the top

## Exercise 7 : std(x)

std(x)
ans =

0.290681065233278



Back to the top

## Exercise 8 : median(x)

median(x)
ans =

0.562762609349455



Back to the top

## Exercise 9 : cumsum(x)

cumsum(x);

Back to the top

## Exercise 10 : prod(x)

prod(x)
ans =

2.065725445935968e-40


end

Back to the top

## Bicycle trip

function set2()

Hint : Use the diff function to create an array of distances between mile markers.

end

Back to lab exercises.

Back to the top