<texit info> author=Roman Putanowicz backgroundtext=http://www.L5.pk.edu.pl/~putanowr/iten.html title=Lab 4: Control flow : loops and conditional statements showbuttons=off </texit> <texit>\input{/home/prac/putanowr/dokuwiki/data/media/wiki/latex/it_preamb.tex} \setcounter{chapter}{3} </texit> <texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>
Repeating instructions - the for loops. Programming vector operations: scalar product, vector norms. Calculation of expressions involving sum and product operators ($ \sum$ and $\prod $ respecitively). Comparison operators and Boolean expressions. Checking conditions - the if command. Tabulating simple and compund functions. Writing programs that generate simple ASCII graphics.
In this lab two basic control structures were introduced - “for” loops and “if” statements. There are some details about these statements that were not mentioned but which can be useful in some programs. They are given as the self study topics below:
Given two sequences: \begin{equation*} \begin{split} a_i &= sin(2\pi i + 1) \\ b_i &= \frac{1}{i+1} \end{split} \end{equation*} Write a script that calculates the value of the expression below: \begin{equation*} \sum_{j=1}^{j=N}\sum_{i=1}^{i=j}b_ja_i \end{equation*}
The distance L from point A to B is to be traversed in stages. At each stage one traverses only 1/3 of the remaining distance. Calculate how many steps it will take before one gets no further than the distance 0.1*L from the point B.
Write Octave function for the graph shown in the figure below. Write a test script for that function.
Write Octave function that checks if a point (x,y) belongs to the shaded area as in the figure below. The function should return 1 if the
point belongs to the area, otherwise 0. Write a test script for that function.
Write a function that finds the second maximum element of a given vector.
Write a function that calculates the area bounded by N-th iteration of
Koch snowflake. The tree first iterations of Koch snowflake are shown
in the figure.
Write a program that writes out at what time (the hour and the minutes) during the day the hour hand and minute hand make square angle.
Write a program that reads in a vector and the writes it out in reverse order.
Write a program that randomly picks $N$ points from a square $[-1,1]\times[-1,1]$ N and calculates the bounding box of them. Hint: use function rand() to generate a random number in range (0,1).
Write a script that writes out all integers divisible by 3 and 4 in the range [a,b] inclusive.
A 2D curve is given in parametric form: \begin{equation*} \mathbf{r}(t) = \begin{bmatrix} x(t) = 5.0 \cos(t)\\ y(t) = 2.0 \sin(t). \end{bmatrix} \end{equation*} Write a function that will estimate the curve length for $t\in[t_1, t_2]$, by approximating it with a polyline with resolution $\Delta t$.
<texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>