Download Full GNU Octave by Example: A Fast and Practical Approach to Learning GNU Octave Ashwin Pajankar PDF All Chapters
Download Full GNU Octave by Example: A Fast and Practical Approach to Learning GNU Octave Ashwin Pajankar PDF All Chapters
com
https://textbookfull.com/product/gnu-octave-by-example-a-
fast-and-practical-approach-to-learning-gnu-octave-ashwin-
pajankar/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/practical-python-data-visualization-
a-fast-track-approach-to-learning-data-visualization-with-python-
ashwin-pajankar/
textboxfull.com
https://textbookfull.com/product/autotools-a-practitioner-s-guide-to-
gnu-autoconf-automake-and-libtool-2nd-edition-john-calcote/
textboxfull.com
Python Unit Test Automation. Practical Techniques for
Python Developers and Testers 1st Edition Ashwin Pajankar
https://textbookfull.com/product/python-unit-test-automation-
practical-techniques-for-python-developers-and-testers-1st-edition-
ashwin-pajankar/
textboxfull.com
https://textbookfull.com/product/practical-cryptography-in-python-
learning-correct-cryptography-by-example-1st-edition-seth-james-
nielson/
textboxfull.com
https://textbookfull.com/product/learning-sas-by-example-a-programmer-
s-guide-2nd-edition-ronald-p-cody/
textboxfull.com
https://textbookfull.com/product/ibm-spss-by-example-a-practical-
guide-to-statistical-data-analysis-second-edition-service-des-
societes-secretes/
textboxfull.com
Ashwin Pajankar
Sharvani Chandu
GNU Octave by Example: A Fast and Practical Approach to
Learning GNU Octave
Ashwin Pajankar Sharvani Chandu
Nashik, Maharashtra, India Pittsburgh, PA, USA
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
Appendix�������������������������������������������������������������������������������������������163
S
tructures���������������������������������������������������������������������������������������������������������163
Cell Arrays���������������������������������������������������������������������������������������������������������164
Operations for Structures and Cell Arrays���������������������������������������������������������165
Polynomials in Octave���������������������������������������������������������������������������������������166
Convex Hull�������������������������������������������������������������������������������������������������������166
Index�������������������������������������������������������������������������������������������������169
viii
About the Authors
Ashwin Pajankar holds a Master of Technology from IIIT Hyderabad. He
started programming and tinkering with electronics at the tender age of
seven, beginning with the BASIC programming language. He was gradually
exposed to C programming, 8085, and x86 assembly programming during
his higher secondary schooling. He is proficient in x86 assembly, C, Java,
Python, and shell programming. He is also proficient with Raspberry Pi,
Arduino, and other single-board computers and microcontrollers. Ashwin
is passionate about training and mentoring. He has trained more than
60,000 students and professionals in live and online training courses. He
has published more than a dozen books with many international and
Indian publishers. He has also reviewed numerous books and educational
video courses. This is his fourth book with Apress and he is working on
more books. He regularly conducts programming bootcamps and
hands-on training for software companies. He is also an avid YouTuber with
more than 10,000 subscribers to his channel. You can find him on LinkedIn.
ix
About the Technical Reviewer
Lentin Joseph is an author, roboticist, and
robotics entrepreneur from India. He runs
a robotics software company called Qbotics
Labs in Kochi/Kerala. He has 10 years of
experience in the robotics domain primarily
in Robot Operating System (ROS), OpenCV,
and PCL. He has authored eight books on ROS,
including Learning Robotics Using Python,
first and second editions, Mastering ROS for
Robotics Programming, first and second editions; ROS Robotics Projects,
first and second editions; and Robot Operating System for Absolute
Beginners. He pursued his Masters in Robotics and Automation from India
and has worked at the Robotics Institute, CMU, USA. He is also a TEDx
speaker.
xi
Acknowledgments
We want to express our gratitude to the technical reviewer and long-time
acquaintance, Lentin Joseph, for helping us make this book better. We
would also like to express our gratitude to the team from Apress. Aditee
Mirashi helped us coordinate the entire book process and Shrikant
Vishwakarma guided us through the editorial process. We are thankful to
Celestin Suresh for giving us the opportunity to write this book.
xiii
Introduction
During my days studying as an undergraduate student, I used MATLAB for
demonstrations in the areas of image and signal processing. MATLAB is
indeed a good tool and a very convenient programming interface for people
who want to focus on subject matters like image and signal processing
because it provides excellent support in these areas for demonstrations.
However, MATLAB is a paid and non-open source product.
GNU Octave is an open source alternative to MATLAB. It has a very
high degree of compatibility with MATLAB in terms of programming.
One of the most desired features of GNU Octave is that it can be used with
Jupyter Notebook. This makes it easier for everyone to write interactive
scripts and share them.
The GNU Octave project has an online repository called the
Octaveforge that hosts many useful libraries for tasks in the areas of signal
and image processing. You can create publication-quality visualizations
for scientific datasets using GNU Octave.
We wrote this book in such a way that novices and beginners will find it
easy to learn the important concepts. The step-by-step approach gradually
increases in rigor and difficulty of concepts and demonstrations. People
working in the areas of data science, signal and image processing, and
scientific domains will find this book extremely useful to get introduced to
GNU Octave and Jupyter Notebook.
While this book has been written for novices and beginners, it
is recommended that you have had some exposure to computer
programming and mathematics since a lot of the concepts in this book are
related to mathematics.
We hope that this book serves you, the reader, well and that you will
enjoy this book as much as we enjoyed writing it.
xv
CHAPTER 1
Introduction to GNU
Octave
We hope you have gone through the table of contents and the preface. If
not, we highly recommend you do so. This is the very first chapter of this
book and we welcome you to the exciting journey of learning GNU Octave.
In this chapter, you will learn the details of GNU Octave such as
its history, applications, limitations, and a comparison with other
contemporary and similar tools. This chapter is mostly dedicated to
general information about GNU Octave and its installation on various
popular OS platforms such as Windows, Ubuntu, and Raspberry Pi
Raspbian. You will not be writing any programs or learning about the
functionality of GNU Octave here. The following is the list of topics you will
learn about in this chapter:
• Applications
• Limitations
• The community
2
Chapter 1 Introduction to GNU Octave
A
pplications of Octave
Octave is used to solve different scientific and numerical computational
problems. It can be used for linear programming and optimization. Octave
is also deployed on many supercomputers because it supports parallel
programming. You can find GNU Octave deployed at supercomputers in
the Ohio Supercomputer Center (www.osc.edu/resources/available_
software/software_list/octave), the Oak Ridge National Laboratory
(www.olcf.ornl.gov/software_package/octave), the and University of
Minnesota (www.msi.umn.edu/sw/octave). In the research community,
Octave is actively used for data analytics, image processing, computer
vision, economic research, data mining, statistical analysis, machine
learning, signal processing, and many more scientific applications. You
will learn how to demonstrate programs pertaining to a lot of the above-
mentioned scientific computing areas with GNU Octave.
3
Chapter 1 Introduction to GNU Octave
4
Chapter 1 Introduction to GNU Octave
5
Chapter 1 Introduction to GNU Octave
I nstalling on Windows
You can install GNU Octave on Windows by downloading and executing
the installable file from the Octave download page at www.gnu.org/
software/octave/download.html. This page has options for 32-bit and
64-bit computers. There is an option for linear algebra for large data but
you will not need it for this book. So, choose the .exe file for installing to
32-bit or 64-bit Windows computers. Other formats, 7z and .zip, are also
available. But you should go for the .exe file. Download the file and execute
it to install GNU Octave. Once the setup has completed successfully,
add the directory location of the Octave executable to the Windows PATH
variable. In my case, it is C:\Octave\Octave-5.2.0\mingw64\bin. It could
be different for you based on the GNU Octave version and your computer
architecture (32-bit or 64-bit).
Once you are done installing it, you need to install Python 3 because
you will need the pip3 utility of Python 3 to install Jupyter Notebook
and Octave Kernel for it. Also, in the end, you will learn how to connect
Python 3 with GNU. You will use the Python 3 interpreter at that time.
Visit the Python 3 download page located at www.python.org/downloads/
and download the setup file of Python 3 for your computer, as shown in
Figure 1-1.
6
Chapter 1 Introduction to GNU Octave
Run the setup file to install Python 3. During installation, check the
checkbox related to adding Python 3 to the PATH variable, as shown in
Figure 1-2.
7
Chapter 1 Introduction to GNU Octave
Also, choose the Customize installation option. This will show you
more options, as shown in Figure 1-3.
Check all the boxes and click the Next button to continue the setup.
Complete the setup. Once done, run the following command at the
Windows command prompt cmd:
python -V
Python 3.8.1
pip3 -V
8
Chapter 1 Introduction to GNU Octave
pip stands for Pip installs Python or Pip installs Packages. Its
name is a recursive acronym. It is a package manager for the Python
programming language. You can install the other needed components
for our demonstrations with pip. To install Jupyter, run the following
command at the command prompt:
The Octave Kernel for Jupyter allows us to run the Octave programs
in a Jupyter notebook. As mentioned, you will see how to work with GNU
Octave and Jupyter in the end of this chapter.
Then using pip3, install Jupyter and the Octave Kernel as follows:
9
Chapter 1 Introduction to GNU Octave
Running the above commands in sequence will install all of the required
packages for this demonstration on the Raspbian OS of Raspberry Pi.
O
ctave GUI
When you install Octave on Windows, you also get a shortcut to the Octave
GUI on your desktop. There is another way to launch it. You can search for
it in the search box of Windows by typing Octave. Two options will appear:
10
Chapter 1 Introduction to GNU Octave
Octave GUI and Octave CLI. Choose the GUI option. On Ubuntu, you can
launch it by searching for it in the search box and clicking the Octave icon
displayed in the search output, as shown in Figure 1-4.
11
Chapter 1 Introduction to GNU Octave
When you launch GNU Octave the very first time on the Raspberry Pi
with Raspbian OS, it shows the welcome message window, as shown in
Figure 1-6.
12
Chapter 1 Introduction to GNU Octave
13
Chapter 1 Introduction to GNU Octave
Click the Next button and you will see the window shown in Figure 1-7.
14
Chapter 1 Introduction to GNU Octave
Click the Finish button and the Octave GUI will be launched.
The GUI Window looks the same on all platforms. Figure 1-9 shows the
Octave GUI window running on a Windows computer.
15
Chapter 1 Introduction to GNU Octave
16
Chapter 1 Introduction to GNU Octave
But first, let’s get started with the customary Hello World! program. Go
to the interactive window and type in printf("Hello, World!\n"); and
then press Enter. It prints the string enclosed in the double quotes in the
interactive window, as shown in Figure 1-10.
You can even create a single-line program of this code and save it.
Go to the editor by choosing the Editor tab at the bottom. Type the same
line as above in the editor and save it. Octave automatically assigns the
.m extension to the file. MATLAB uses the same extension. The simple
program is shown in Figure 1-11.
17
Another Random Scribd Document
with Unrelated Content
64. My father has a gig to make; the more him pare it the bigger it
get. 18
—Hole.
—Fire.
66. My father have one thing in his hand and throw it and it support
the whole of Jamaica. 20
—Corn-grain.
b) One prisoner stan’ pon Marley hill; ten policemen go fe tek him
down; two bring him to de station do, an’ de sentence pass pon de
finger-nail.
—Ackee; this refers to the common warning that the fruit is safe to eat
only after it has ripened and split in the sun. [191]
69. My father plant a acre a kasava; only one white belly rat a eatey
off.
—Grater for preparing kasava meal.
70. My father give me one root kasava an’ a quart of fine salt; if I
don clever I wouldn’t taste it.
a) I put on one coco on the fire to boil and I put in a gallon of salt,
and the salt never tasted it.
b) I have a t’ing and don’t care how much salt I put in it, when I go
to eat it I have to put salt on it.
71. My father gave me some seed to sow; the ground is white and
the seed is black. 22
—Black ink on white paper.
72. My father was in Green Island cutting chip and the chip never
fly. 23
—Clock.
73. Mother put on a pot of food to boil; the top boil before the
bottom.
—Pipe.
74. Going up to town my face turn to town; coming back from town
my face turn to town.
—Climbing a tree.
75. I was going up to town one morning, met a man; I tell him
’Mawnin’ and he wouldn’t speak to me, and when I was coming back
early in the evening he speak to me.
—Trash, noiseless to the tread when cold, crackles when warmed by the
sun. [192]
76. I was going up Sand-hill and saw a man and suck his blood and
throw him over the wall. 24
—Orange.
77. When I was going up to town I met a man; his head is fire an’
his mouth is bone. 25
—Rooster.
b) Got to a gentleman’s yard and his mouth was hard and his beard
was flesh.
78. I was going over Dingledown hill and I saw a grey horse.
—Moon.
79. Picking juketa (?) going to town, picking juketa coming from
town and can’t get my hands full.
—Dew and sweat. [193]
—Fingers.
81. I was going to town; I mash a plate and when I was coming
back I found it new.
—Ants’ nest.
82. As I was going up to town I hear the bells of heaven ring; man
tremble, beast tremble, cause the devil to break his chain.
—Earthquake.
—Cocoanut.
84. A man was going to Kingston, saw two roads and took both. 26
—Trousers.
85. I heard that my father was dead in Kingston; I went there and
took a piece of his bone and made increase.
—Kasava root.
88. I went to town, I walk in town, I eat in town, and yet I don’t
know town.
—A woman was breedin’. She went to town an’ after she come home the
baby born, grow a big man, don’ know town.
89. A man going to town and he face town, and when he coming
back he face down to Montego Bay.
—Train running between Kingstown and Montego Bay. [194]
90. A man going up to town; he walk on his head going up, he walk
on his head going back. 27
—Horse-shoe-nail.
92. Four men going up to town; all were talking and not one could
understand the other.
—Four buggy wheels.
93. Four bredder walk a road and not one can touch. 28
—Four buggy wheels.
94. Some white ladies were walking to Kingston, and all the walk
they walk they couldn’t catch each other.
—Mile-posts.
95. Three brothers in one house and never see each others’ face
until dead.
—Three beans in one castor-oil pod.
96. Two sister on ribber side; no one could never wash the other.
—Two bottles.
97. Two sawyers were sawing from morning till night and never saw
a bit of dust. 29
—Clock. [195]
98. Three man start fe go a heaven; one go half way an’ turn back,
one go right up, and one no go at all.
—Fire: spark, smoke and ashes.
99. A man walk around four corners of the world and make a house;
rain come catch him a door, dew fall on him, sun burn him, and he
have no shelter of his own.
—Ladder.
101. A man work for rich and work for poor and yet his head
outside.
—Nail-head.
102. There was an old man that live never building house till rain
come. 30
—John Crow: as soon as rain come he begin to cut posts, say he will
build him a house. When sun comes out, he come to dry himself; never
build house any more.
—Sea.
106. Born from de worl’ mek an’ nebber a month ole yet. 32
—Moon.
110. Holler belly mumma, humpback pupa, pickney wid t’ree foot.
—Cooking-pot.
114. I think I will shoot God, and God say I mus’ shoot the earth. 35
—Banana shoot.
115. I was tying mat ever since an’ I never lay down on one.
—Pumpkin-vine.
118. And smart as little Tommie be, one man kill the whole world.
—Mr. Debt.
119. Woman have a chile an’ fust begin larnin’ larn him fe t’ief. 37
—Hawk. [197]
124. John Redman tickle John Blackman till him laugh puco-puco. 38
a) A red man tickle a black man make him belly boil up.
125. Mr. Redman box Mr. Blackman make Mr. Whiteman laugh.
—Fire, baking-pan and bammie.
126. The white man take a red cloth tie his head.
—Tooth and gum.
127. Mr. Blackman was going to town; him drop him kerchief an’
couldn’t pick it up.
—Crow drops a feather.
128. Miss Nancy was going to Kingston; she drop her pocket
handkerchief never turn round to pick it up.
a) Miss Nancy was going up-stairs and she lose her pocket
handkerchief and she would not turn round to pick it up.
129. Little Miss Nancy sit at the pass; everyone that come give him a
kiss.
—Fly. [198]
130. Little Miss Nancy tie up her frock and wheel round three times.
—Turn-stick in the pot.
132. Miss D. June (?) cutting wood for a year, never get a bundle.
—Woodpecker.
—Bottle.
134. Aunty Mary cut two packey, not one bigger than the other. 39
—Heaven and earth.
a) Ole man Brenta sit on a stump, cut two packey not one bigger
than the other.
—Cloud on the earth (?).
—Boy climbing after a cocoanut; nut falls before boy comes down.
a) Look through a diamond I see the dead carry the living. [199]
137. A hen have six chickens; and hold the hen, the chickens cry.
—Guitar with six strings.
138. Two horses were galloping and neither of them could catch one
another. 42
—Two mill-rollers.
—Rooster; when one crows at one end of the island, another answers at
the other end.
—Purse.
—Road.
161. A ’tump in a pond; all the rain can’t cover the ’tump-head.
—Turn-stick in the pot.
162. There’s a rope and every bump a sheet of paper.
—Pumpkin-vine.
—Smoke.
—Lamp.
169. Hairy within and hairy without; lift up your foot and poke it in. 47
—Stockings.
170. Outside black, inside red; cock up your foot and poke it in. 48
—Boot.
173. Green as grass, not grass; stiff standing in the bed; and the
best young lady is not afraid of handling it. 51
—Onion.
176. High as the world; red as blood but not blood; blue as indigo;
but not indigo; high as granadillo temple.
—Rainbow.
177. When it come it does not come; when it does not come it
come. 52
—Rat and corn.
182. Six is in, the seventh is out; set the virgin free.
184. Two peepers, two pokers, two waddlers, and one zum-zum. 54
—Cow.
187. Half a ’tumpy sit down on ’tumpy; when a go, a don’ see
nothing but half a ’tumpy.
—Broken bottle on stump.
188. Climb up Zion hill, pick Zion fruit, come down Zion hill, drink
Zion water.
—Climbing a cocoanut tree, picking the nut, coming down, drinking the
milk.
—Flea.
194. Miss Witty wit and wit till she wit out her last wit.
—Needle and thread.
—Making a broom.
201. Limb fell lamb; down fell lamb in the cow coram.
—Limb falls, knocks lamb into the cow-dung.
202. If I had my pretty little caney, bigny-pigny could not kill kum-
painy.
—If I had my revolver, the wild hog could not kill my dog.
203. I was going out and I saw some pigs, and if I had my hansom-
cansom I would carry home some bigny-pigny.
—If I had my gun, I would carry home some pigs.
204. I send for my man Richard to bring me tomery-flemery-doctory
to mortify unicle-cornicle-current out of my pinkicle-pankicle-
present. 58
—To bring my three dogs to drive three pigs out of the garden.
205. There is a boat an’ in that boat a lady sat, an’ if I should tell
you the name of that lady I should be blamed, for I’ve told you the
riddle twice. 59
207. I an’ my dog ben up the lane catching a buck an’ a doe.
Whoever tell me my dog’s name, there is my dog. 61
208. Megs, Pegs an’ Margaret is my true lover; but it’s neither Megs,
Pegs nor Margaret.
—Anne is my lover.
210. There are 4000 people to draw in one carriage; how can they
do that?
—Mr. & Mrs. Thousand and their two children.
211. Mr. Lets was walking and Mr. Lets was riding and Mr. Lets was
walking again. Can you tell me who the gentlemen were?
—Horse, master and dog, all named ’Lets’.
212. My father has a long bench in his house, an’ to guess me how
many people sit on that bench.
—One man named ‘More’. (The trick is, at each guess to say M o r e .)
—A horse named H o n e y .
216. I was going up Hampton lane, I met a man have seven wives;
the seven wives have seven sacks, the seven sacks have seven kits,
how many were there going to Hampton? 64
—Only one—I.
217. A duck before a duck, a duck after a duck, a duck in the midst
of two ducks. How many ducks was going along?
—Three.
218. I was travelling and six ducks flying, one before the five; and I
took up my gun and I shoot one of the ducks and drop on the
ground. Guess how many ducks remain? 65
—None; the rest fly away.
219. A parson and his daughter, a doctor and his wife; and there is
three apples to share among them. How will they share it? 66
—Each takes one; the parson’s daughter is the doctor’s wife.
220. Run, Ricky, run; run up the Ahe river, run; run with a long trail,
run up the Ahe river, run; run, Ricky, run? How many r’s in that?
221. Mr. Parott was sitting on a tree; some pigeons were flying by.
The pigeon say, “Good morning, Mr. Parrot.” The parrot say, “Good
morning, Mr. Hundred.” The pigeon say, “I’m not ‘hundred’; want
twice as much, half as much, quarter [209]as much, and you, Mr.
Parrot, to make a hundred.” Tell me how many pigeons were flying. 67
—Thirty-six.
222. I hire laborers for a shilling a day; I get twelve laborers. I give
a man two pence, a woman ha’ penny, a pickney one farthing. How
many of each do I hire?
223. My father gave me a horse to go sell for ten pounds and to eat
my breakfast out of the money and bring home the same ten
pounds. How could I do that?
—Take the shoes off the horse and sell them separately.
a) The same story with a fox, goose and bag of corn. [210]
225. My fader got six sheep. He send his son to de pen. ‘My son, go
an’ count me six sheep, but you musn’ count me “one, two, t’ree,
four, five, six”. You musn’t count “four an’ two, six”. You musn’t
count “t’ree an’ t’ree, six”. You musn’ count “five an’ one, six”, but
count me my six sheep!
—Dis, dat, de other,
De ewe, de ram, de wether.
226. I gwine to make a dance; I want you there. You mus’n’t come a
day, you mus’n’t come a night, you mus’n’t ride a horse, you mus’n’t
ride a mule, you mus’n’t ride a jackass. An’ if you come, you mus’n’t
come into me house an’ you mus’n’t stay outside. 69
—You must come riding a cow, between day and night; and when you
come, stand on the threshold, neither in nor out.
[211]
249. Give a number that isn’t even: cut off the head, you get it
even; cut off the tail, your mother’s name you shall find. 85
—Seven, even, Eve.
250. What word of one syllable, take away two letters and leave two
syllables? 86
—Plague, ague.
251. A word of one syllable which, when two is taken off, ten
remain.
—Often, ten.
255. What is it that we see every day, King George himself sees, and
God never sees? 88
—Our equal. [216]
256. What is that which if you have not you would not like to get
and if you have you would not like to lose? 89
—A bald head.
257. What is it, when Adam was four days old it was four days old,
and when Adam was four-score years and four days old it remained
four days old? 90
—Moon.
258. What is that which Christ had not, Napoleon had, Kaiser has
and no woman ever has?
—A wife.
259. What is it that is too much for one, enough for two, and
nothing at all for three?
—A secret.
260. The river is bank to bank; how will you get over?
—By bridge.
261. Suppose all the tree was one tree and all the man was one man
and all the axes one ax; and suppose the one ax fell the one tree
and the one tree kill the one man, who would leave to tell the tale?
—Women.
262. Higher than God, lower than the devil; the dead feed on it but
not the living. 91
—Nothing.
263. There was a woman born, live an’ die; never go to corruption,
never see God face.
—Lot’s wife. [217]
264. There is a thing on earth that God could do but didn’t, the devil
had’nt got the power, and men do it. 92
—Baptism.
271. Mr. Bigger has a baby; out of Mr. Bigger and his baby which is
the bigger?
272. If an elephant’s four feet cover four acres of land, what will his
tail cover?
—The skin.
273. What money in the world is the hardest money to change?
—Matrimony.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com