Chapter 4: Rationalizing: Octave Scripts

Understanding disp and input

b)

d)

e)

Note that c) will likely give an error later.

Understanding statements and Boolean operators

1

a)

f)

g)

2

1 1 1 3 1 5 2 1 2 3 2 5

3

Line 5 does not match the while statement

 

Line 6 does not match the for statement

 

m is not incremented which will lead to an infinite loop

4

Line 1: input must have the optional argument 's' for string inputs

 

Line 3: is not a valid expression (use strcmp instead)

 

Line 5: the elseif statement evaluates a Boolean

Printing with printf

1

a) blank

b) Hello Worl

c) Hello Worl

 

d) 2

e) 2.000000

f) 2.000000e+000

Get GNU Octave now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.