<texit info> author=Roman Putanowicz title=Lab 3: Defining and using functions backgroundtext=http://www.L5.pk.edu.pl/~putanowr/iten.html showbuttons=off </texit> <texit>\input{/home/prac/putanowr/dokuwiki/data/media/wiki/latex/it_preamb.tex} \setcounter{chapter}{2} </texit> <texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>
Octave syntax for defining functions. Defining functions versus calling it - the most common mistakes. Functions and m-files - Octave mechanism for building libraries of functions. Name scopes, local variables versus global variables. Passing variables to functions by value. Introduction to plot command - ploting scalar functions in 2D. Setting selected plot paramters - axis range, plot color, basic annotations. Pausing Octave scripts with pause()
.
In this lab two important topics are touched: defining user functions and plotting in Octave. Functions are important because they are basic building blocks of Octave programs, they help to make the code easier to write, maintain and reuse. During the lab only the most important aspects of Octave functions are exercised. That is enough for writing simple programs, however sometimes more advanced constructs are necessary. Below some ideas for self-study related to Octave functions are given:
The second topic just touched in this lab is Octave support for making plots. One can use Octave built-in support for plotting or one of several extension packages, for instance Octaviz. Below are some ideas for self-study:
* Lab 5 handouts – another course lab handouts (in Polish), a lot of simple examples
Write a function that calculates the area of segment of a circle knowing its central angle and the circle radious.
Solution
Write a function that normalizes a vector.
Solution
Write a script that plots funcion f(x) for x in the range [-5:5] \begin{equation*} f(x) = \frac{1}{1+(x\sin(x))^2} \end{equation*} Annotate the plot as shown in figure <texit>3.2</texit> below.
Write a function that calculates arithmetic, harmonic and geometric average of two positive numbers.
Write a function that calculates the volume of a regular tetrahedron with the edge length equal x.
Write a function that caluclates the surface area of a regular N-gon inscribed in circle of radiurs R.
Write a function that calculates the time from the start to the fall for a projectile in a skew throw, given the initial velocity v and the angle $\alpha$.
Write a function that calculates the area between 7-gon and its circumcircle. Reuse the function written for Ex. 3.2.3.
Write a function that plots the trajectory of a projectile in skew throw.
Write a function that calculates the maximum deflection of a beam shown in figure below. The beam length L, crossection moment of inertia J ,material elasticity modulus E,
and the load density q are the function's input parameters. Find a suitable reference for the formula of the beam deflection.
Write a function that calculates the barycentirc coordinates (aka area coordinates)
of a point P(x,y) with respect to the triangle ABC shown in figure below.
Given a parabola of the form
y(x) = a^2 - x^2 a=const
write a function that depending on value “a” calculates the volume inside the surface made by rotating the part of the parablola for y>=0 around the X-axis.
Hints: Search for Papus' s centroid theorem and Simpson rule.
<texit>\begin{comment}</texit> prev | up | next <texit>\end{comment}</texit>