<texit info> author=Roman Putanowicz backgroundtext=http://www.L5.pk.edu.pl/~putanowr/iten.html title=Lab 2: Getting started with Octave showbuttons=off </texit> <texit>\input{/home/prac/putanowr/dokuwiki/data/media/wiki/latex/it_preamb.tex} \renewcommand{\chaptername}{Lab Handouts} \setcounter{chapter}{1} </texit> <texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>
Running Octave in interactive mode. The difference between Octave prompt and
shell prompt. Command line editing in Octave; command history. Octave as
scientific calculator; evaluating arithmetic expressions in interactive mode.
Variables and assignment operator. Writing Octave scripts. Running Octave
scripts from shell command line and from Octave interactive session.
Octave simple I/O: disp
and input
commands.
Defining vector variables, reading vectors via input
command.
Defining arithmetic sequences the :
(colon) operator.
The goal of this lab is to introduce the basic concepts of programming in Octave, especially the working of the assignment operator. While some basics of defining scalar and vector variable are shown, there is a lot of topics about vectors1) and matrices that are not covered. Octave is a matrix-based language, which means that matrix operations are built-in into language core, it provides special syntax for handling matrix variables and functions that can operate both on scalar and matrix arguments. Mastering operations on matrices can speed-up programs development, make them shorter and more easy to understand and in most cases make them execute faster. Below are some ideas for self study related mostly to operations on vectors:
printf
.*, +, -
on vectors.^, *, /, +, -
and their version prefixed with “.
” (dot), i.e. “.*
”.
Using Octave in interactive mode calculate the value of the expression:
<latex>
$ \Large\begin{equation*}\text{.}\quad\quad \sin(a)^{\sin(b)+1}
\end{equation*}\normalsize
$
</latex>
for the following pairs of values (a,b):
(0.7, 1.0) (0.1, 3.0) (0.3, -0.5)
Write a script that asks user to enter coordinates of two vectors and then calculates and displays the Euclidean norm, scalar product and vector product of these vectors.
Solution.
Write a script that given initial term and common difference of successive members of an arithmetic sequence displays N initial terms of that sequence.
Solution.
Write a script that allows the user to translate between radians and degrees.
Write a script that calculates the surface area of a cone knowing its radius and height.
Write a script that reads in coordinates of three points in 3D space and calculates the area of a triangle with these points as vertices.
Hint: Check out the geometric meaning of vector cross product magnitude.
Write a script that calculates the distance on the Earth's surface from a given point to the North Pole. Assume that the point's geographic coordinates are given with minute resolution.
Write a script that for any given argument x calculates the value of a function shown in the figure
<texit>2.1</texit>
below.
Write a script that reads coordinates of three points A, B, C in 2D and calculates the distance from the point C to the line defined by the segment AB.
An electric field is created by three charged elementary particles with charges respectively
q_1 = 2 [C] q_2 = -4 [C] q_3 = 12 [C]
located as shown in figure <texit>2.2</texit>
Write a script that calculates the E-field at point (x,y).
The “pyramid” shown in the figure <texit>2.3</texit> is built from square plates with the material area density $\rho_s$ [kg/m^2]. Write a script that calculates total weight of a pyramid H blocks high and with block dimension equal a.
Bob the Builder is going to build a plank fence
around the yard shown in the figure
<texit>2.4</texit>
below. He wonders how many planks are needed.
Write a script that given the yard dimensions R, L and H as well as the plank's width w will calculate the number of planks that needs to be ordered.
<texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>