Вы находитесь на странице: 1из 9

Name: Schedule:

Course & Year:

EXPERIMENT NO. 1
INTRODUCTION TO GNU OCTAVE

I. OBJECTIVES
A. To be familiar with the user interface of GNU Octave
B. To learn the different functions and features of GNU Octave
C. To study the basic syntax for GNU Octave
D. Start Octave program and solve simple problems in the command window
E. Understand the order of operations in Octave

II. DISCUSSION
GNU Octave is a high-level interpreted language, primarily intended for numerical
computations and analysis. It provides capabilities for numerical solution of linear and
nonlinear problems for performing other numerical experiments. It also provides
extensive graphics capabilities for data visualization and manipulation. GNU Octave is
normally used through its interactive interface, CLI and GUI, but it can also be used to
write non-interactive programs. GNU Octave is an official GNU project, and the source
code is released under the GNU General Public License (GPL). In simple terms, this
means that you are allowed to use the software for any purpose, copy, and distribute it,
and make any changes you want to it.
Figure 1. Octave opening window
Octave uses several display windows. The default view, shown in Figure 1, includes in the
middle a large command window, located right, the variable editor and located left the
current folder window, workspace and the command history.

Command Window
The command window is located in the center pane of the default view of Octave screen, as
shown in Figure 1. The command window offers an environment similar to a scratch pad. Using
it allows you to save the values you calculate, but not the commands used to generate those
values. If you want to save the command sequence use the editor window to create an M-file.

Command History
The command history window records the command you issued in the command window.

Workspace
The workspace window keeps track of the variables you have defined as you execute
commands in the command window.

Current Folder
The current folder window lists all the files in the active directory. The default for the location of
the current folder varies with your version of the software and the way it was installed. The
current folder can be changed by selecting another directory from the drop-down list located
next to the directory listing or by browsing through your computer files.

Writing and running a program


Figure 2. Editor Window
1. Go to editor window by clicking the editor tab beside Command Window at the center
bottom of the default window.
2. On the editor window simply write the code.

3. To run the program just click save file and run.

III. EXERCISES
1. Volume of a cube
Write a program that computes the volume V of a cube with sides of length L = 4
cm and prints the result to the screen. Both V and L should be defined as
separate variables in the program. Run the program and confirm that the correct
result is printed.
2. Area and circumference of a circle
Write a program that computes both circumference C and the area A of a circle
with radius r = 2 cm. Let the results be printed to the screen on a single line with
appropriate text. The variables C, A and r should be defined as separate
variables in the program. Run the program and confirm that the correct results
are printed.

3. Volumes of three cubes


a. Use the linspace function to compute three values of L, equally spaced on
the interval [1,3].
b. Carry out by hand the computation 𝑉 = 𝐿3 if L is an array with three
elements. That is, compute V for each value of L.

c. In a program, write out the result V of 𝑉 = 𝐿3 when L is an array with


three elements as computed by linspace in a. Compare the resulting
volumes with your hand calculations.

d. Make a plot of V versus L.


4. Average of integers
Write a program that stores the sum 1 + 2 + 3 + 4 + 5 in one variable and then
creates another variable with the average of these five numbers. Print the
average to the screen and check that the result is correct.

5. Formatted print to screen


Write a program that defines two variables as x = pi and y = 2. Then let the
program compute the product z of these two variables and the the result to the
screen as:
IV. CONCLUSION

Вам также может понравиться