ALGORITHMIZATION AND PROGRAMMING

winter semester 2021/2022

Tutorials - Course Schedule    (for Lectures, see here)


Exercises



Week 1 - introduction to Matlab, elementary computations

themes:

examples: dialog window, arrays

exercises:

HW: Exercises - prepare the formulas for computation of the problems from the second paragraph


Week 2 - Matlab: scripts, plots

themes:

examples: input and output (I/O), plots

exercises (do not use if, for or while commands; use vectorization instead):

HW: Exercises - the first paragraph and any 2 problems from the second paragraph


Week 3 - Matlab: flow control

sources:
a short list of commands, relational and logical operators,
conditional control,
loop control

examples

exercises:

successively program these Exercises - paragraphs 3 (branching) and 4 (loops)
- learn both ways of programming the loops: either explicit (using command for or while), or vectorized (using Matlab functions on vectors)

HW: Exercises - one problem (of your choice) from the third paragraph (preferably chosen from the last three problems of the third paragraph) and one or two problems from the fourth paragraph (loops: if possible, compare vectorized solution of the problem with explicit loop - an example)


Week 4 - Matlab: recapitulation

You should be able to program any of these Exercises - all paragraphs.


Week 5    22. 10. 2021

the first assessment test:

You will be given two exercises similar to these and you will write down the solution on a piece of paper, without use of a computer or any other tool (calculator, textbook, ...). However, you can print and use this list of commands and this list of operators and functions as a quick help.

For some suitable problems, you will be asked to solve them both with and without using Matlab vector functions like max, mean, sum or find (i.e. you should be able to write a program for performing these vector operations element by element) - an example.


Week 6 - Tutorial cancelled (Dean's day)


Week 7 - Matlab: functions

exercises:


Week 8 - functions

using functions: exercises

advanced exercise: write a script for the maze route algorithm described at the first lecture.
Use function for computing possible moves of a knight from a given position, for example:

function [nr, nc] = NewPositions(r,c, N)
%
% input: 
%   r, c ... row, column of a chess position
%   N    ... size of the chessboard
% output:
%   nr, nc ... column vectors of possible knight moves 
%      nr(k), nc(k) ... a possible new position

   ...

end

Then use this function in the main script, that asks for input (i.e. starting and target positions) and prints the output: minimum number of knight moves to reach the target.

Then you can change the script so that for given starting point, for every position of a chessboard of a given size N, it computes the minimal number of knight moves to reach the target.


Week 9 - recapitulation

- exercise algorithms using functions


Week 10    26. 11. 2021

The second assessment test, or the first assessment test, repeated.

the second assessment test: you will be given several problems similar to these to show that you can program your own functions and that you can write numerical algorithms using them.

You can use Matlab (Octave) to debug and check your scripts, you can use tutorials on internet to recall some operator, command or function. However, you are not supposed to look up SOLUTIONS of the given problems elsewhere - your scripts are expected to be YOUR WORK, not a copy-pasted scrips made by someone else.


Weeks 11 - 13 - Consultations

An opportunity to repeat an assessment test.


References

SW

Matlab - student version can be installed from download.cvut.cz
                (it can be used from the CTU network only)
GNU OCTAVE - free, similar to Matlab


Last updated: 6. November 2021