1. Introduction           


 

1.1           Getting oriented

1.2           Getting an overview of this book

1.3           Understanding computer architecture

1.4           Approaching the task of programming

1.5           Deciding if a program is needed and whether you should write it

1.6           Being as clear as possible about what your program should do

1.7           Working incrementally

1.8           Being open to negative feedback

1.9           Programming with a friend

1.10        Writing concise programs

1.11        Writing clear programs

1.12        Understanding how the chapters of this book are organized

1.13        Using the website associated with this book

1.14        Acknowledging limits

 

 

top of page

1.8 Being open to negative feedback

 

Code 1.8.1

 

x = [1 2 3 4 5 6 7 8];

y = [0.39  0.47  0.60  0.21  0.57  0.36  0.64  0.32];

plot(x,x,'ko-')

xlim([.999 8])

xlabel('Session')

ylabel('Score on Test')

 

Output 1.8.1

 

 

Code 1.8.2

 

x = [1 2 3 4 5 6 7 8];

y = [0.39  0.47  0.60  0.21  0.57  0.36  0.64  0.32];

plot(x,y,'ko-')  % Correction made here.

xlim([.999 8])

xlabel('Session')

ylabel('Score on Test')

 

Output 1.8.2

 

 

 

 

 

top of page

1.11 Writing clear programs

 

 

Code 1.11.1

 

% Largest_So_Far_01

 

% Find the largest value in the one-row matrix d.

% Initialize largest_so_far to minus infinity.

% Then go through the matrix, by first setting i to 1

% and then letting i increase to the value equal

% to the number of elements of d, given by length(d).

% If the i-th value of d is greater than largest_so_far,

% redefine largest_so_far as the ith value of d.

% After going through the whole array, print out largest_so_far.

 

d = [7 33 39 26 8 18 15 4 0];

largest_so_far = -inf;

for i = 1:length(d)

    if d(i) > largest_so_far

        largest_so_far = d(i);

    end

end

largest_so_far

 

Output 1.11.1

 

largest_so_far =

 

    39