You are on page 1of 3

Octave Introduction and Control Statements Exercises

1. In Octave set a=2, b = 7, c = 13 and multiple a * b * c as shown below in Figure 1.

Figure 1: Simple multiplication in Octave

2. In Octave set, d = 1.2 * sin ((40*pi/180 + log(2.4^2)) and set, e = 2.7 * cos(40*1/60). Multiply
both d and e together.

3. Create a Vector of numbers between the range of 1 to 200, with a spacing of 5 between each
number. The result should look like Figure 2 below. Hint: Refer to the slides on “The Colon
Notation” to achieve this

Figure 2: The output of a vector

4. Create a plot of a SINE wave in Octave that has 200 vector elements on its X axis. The plot
should have a title and a label on both the X and Y axis.

5. Create a COSINE wave with 200 Vector elements on its X axis.

6. Combine both a SINE wave and COSINE Wave on the same plot. The Plot should have a title and
label on both the X and Y axis.
Control Structures

7. Write a program that takes in a users input into the command line.

If the user inputs the number 0 the program outputs the text, “You inputted zero”.

If the user inputs the number 1 the program outputs the text, “You inputted one”.

If the user inputs the number 2 the program outputs the text, “You inputted two”.

If the user inputs anything else the program outputs the text, “Something else”.

8. Write a program that helps the user count his/her change. The program should allow the user
to input how many 50 fils, 100 fils, 500 fils and 1, 5, 10 and 20 BD notes the user has into the
command line. The program should tell the user how much money he/she has expressed in
BHD.

9. Write a program that allows the user to input the number of hours and minutes they have
worked this week. Your program will convert the hours and minutes into seconds and output
the results.

10. Write a program that takes in a user’s input. The user will input the mark they got in an exam. A
comment will be outputted based on the Grade the student entered.

You will also need to use the control operator and logical operators.

Operator Meaning

== Equal to

> More than

< Less Than

>= More than and equal

<= Less than and equal

<> Not Equal to

Operator Meaning
And Both sides must be true

Or One side or other must be true

Xor One side or other must be true but not both

Not Negates truth

If the user inputs any number between 100 and 85 the program outputs the text, “Fantastic you got an
A”.

If the user inputs any number between 84 and 70 the program outputs the text, “You got a B, good
grade”.

If the user inputs any number between 69 and 55 the program outputs the text, “You got a C, try to up
your work to do better next time”.

If the user inputs any number between 54 and 40 the program outputs the text, “D was your score, I will
be sending a note home to your parents”.

If the user inputs any number between 0 and 39 the program outputs the text, “F, oh no, I can’t believe I
got an F”.

If the user inputs anything else the program outputs the text, “You’re a silly, you entered something
wrong”.

If grade <= 100 & grade >= 85

You might also like