Scientific Computing With Octave

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Scientific Computing

with Octave
Octave, GNUPlot and Other Tools
Dr. Michael Rakijas
Benedict G. Archer
Sept. 18, 1999

Octave's Uses and Value


Analysis Tool
solving numerical linear algebra problems
finding the roots of nonlinear equations
integrating ordinary functions
manipulating polynomials
integrating ordinary differential and differential-algebraic equations

System Simulation Tool


Control Theory
Signal Processing
Image Processing
Audio Processing

Computational Engine
Programmable
Easily Extendible
Graphical Comparison Tool

Saving, Loading and Graphics


Save the workspace
octave:10>save test
octave:11>clear
octave:12>who

Loading a previously saved workspace


octave:13>load test
octave:14>who
*** local user variables:
C

oct_home

Plotting a sequence of numbers and annotating it


octave:16>for k=1:20;d(k)=sin(2*pi*k/20);end
octave:17>plot(d)
octave:18>xlabel("x text");ylabel("y text"); # Actually MATLAB syntax
octave:19>replot
octave:20>gset xlabel "xlabel"; gset ylabel "ylabel"; # Normal Octave syntax
octave:21>replot

Example 1: Basic Problem Solving


Simple linear algebra problem: 3 ind. equations in 3 unk.
x1-12x2-4x3=-5; -20x1+3x2-5x3=-119; -14x1-3x2-17x3=-53
This can be represented using the matrix equation Ax=b
Using Octave, this can be solved as follows:
octave:48>A=[1 -12 -4;-20 3 -5; -14 -3 -17]
A=
1 -12 -4
-20 3 -5
-14 -3 -17
octave:49>b=[-5;-119;-53]
b=
-5
-119
-53
octave:50>A\b
ans =
7.0000
2.0000
-3.0000

Example 2: Basic Signal Processing


Define a basic sine wave; x(k)=3sin(2 k/10) as
k=1,2,3...256; Type
octave:51>for k=1:256;s(k)=cos(2*pi*k/10);end

Generate some Gaussian noise


octave:52>n=2*randn(256,1);

Add it to the signal


octave:54>x=s+n;

Take the magnitude of the Fourier transform of the time


series
octave:55>p=abs(fft(x));

Plot the result


octave:56>plot(p)

Resulting Plot

Example 3: Editing a script


Create a basic text file, a few comment lines (#) to start
Add a string of commands legal Octave commands
Save the file somewhere on the Octave LOADPATH
(type "path" at the prompt) with a .m suffix, like
testum.m
Type "testum" at the prompt, the commands will execute
Type "help testum", the first comment lines will display
octave:22>testum
a=7
b=3
ans = 21
octave:23>help testum
testum is the file: C:/doc/misc/expopres/testum.m
This is a text file; This might a message I want to see quickly
if I need to remind myself of the contents of this file later on.

Example 4: Some Interesting Plots


clg
domain = [-3:0.2:3];
range = [-5:0.2:5];
[x,y] =
meshgrid(domain,domain);
r = sqrt(x.^2 + y.^2) +
0.00001;
z = sin(pi*r)./(pi*r);
title('Sombrero')
mesh(z)
pause

clg
t = range;
s = sinc(t);
s2 = s'*s;
mesh(t,t,s2)
pause
clg
c = cos(t);
c2 = c'*c;
mesh(t,t,c2)
pause
contour(c2)
pause

clg
sq = t.^2;
sq2 = sq'*sq;
mesh(t,t,sq2)
pause
clg
mesh(t,t,1-sq2)
pause
S = fft(log(t));
clg
plot(S)
pause
clg
t = 0.1:0.1:100;
polar(t,t.*log(t))

Resulting Plots

Resulting Plots (cont.)

Resulting Plots (cont.)

Conclusion
Octave is an accessible, easy to use
numerical computation utility that can
span the uses of the high school level to
that of the complex tool needed by
engineers
We've shown how to start from scratch,
assemble the utilities necessary to set up
this powerful tool on your home
computer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy