Ahmed
Ahmed
الجامعة اإلسالمية
Faculty of Engineering
Department of Electrical كلية الهندسة
Engineering قسم الهندسة الكهربائية
ENGR 3032
SCIENTIFIC COMPUTING LANGUAGES
Winter Semester 2024
EXPERIMENT 6
Logical Function and Selection Structures
LAB REPORT
[CO_6, PI_6_3, SO_6]
Submitted To
Mr. Muhammad Uzair
Submitted By
Ahmed Younes , 431014103
Section No:2542
Plot the sinc functiony(x) for values of x from -3π/2 to +3π/2. Choose an adequate
increment/spacing to create smooth curves. Use the find function to separate the x
values and calculate the corresponding y(x). Choose adequate x and y-labels and
name the resulting plot as 'The sinc function'.
Task 2:
In order to have a closed geometric figure composed of straight lines, the angles in the figure
must add to (n-2)(180) degrees, where n is the number of sides.
a) Write a script file and create a vector called n from 3 to 6 and calculate the angle sum
from the formulae.
b) Write a script that prompts the user to select one of the following figures from a
menu: triangle, square, pentagon, and hexagon. Use the input to define the value of n
via a switch/case statement; then use the value of n to calculate the sum of the interior
angles from the formulae above.
Task 3:
The following information was collected from a set of thermo-couples. The first column
consists of time measurements (one for each hour of the day), and the remaining columns
correspond to temperature measurements at different points in a process.
(a) Write a program that prints the index numbers (rows and columns) of temperature data
values greater than 84.0. (Hint: You’ll need to use the find command.)
(b) Find the index numbers (rows and columns) of temperature data values less than 70.0.
(c) Find the maximum temperature in the table and the corresponding hour value and
thermocouple number.
Hour Temp1Temp2 Temp3
---------------- ----------- ---------------------
1. 65.00 58.529 87.811
• Task 1 involved plotting the sinc function, covering the range of x values from -
3π/2 to +3π/2 with smooth curves and suitable spacing. The corresponding y(x)
values were calculated using the find function, and the plot was labeled as "The
sinc function".
• In Task 2, a script was created to calculate the angle sum for closed geometric
figures composed of straight lines. The script utilized a vector n ranging from 3 to
6 to represent the number of sides. The angle sums were computed using the
formula (n-2)(180). Additionally, a menu-based script was implemented to allow
the user to select a figure (triangle, square, pentagon, or hexagon) and calculate
the sum of the interior angles based on the chosen figure.
• Task 3 involved analyzing temperature data collected from thermocouples. A
program was developed to fulfill the following objectives:
• Identifying and printing the index numbers (rows and columns) of temperature
data values greater than 84.0, using the find command.
• Finding and displaying the index numbers (rows and columns) of temperature
data values less than 70.0.
• Determining the maximum temperature in the dataset, along with its
corresponding hour value and thermocouple number.
• Task 4 highlighted the limitations of the inverse sine (asin) and inverse cosine
(acos) functions, which are only valid for inputs between -1 and +1 due to the
restricted range of sine and cosine values. It was noted that MATLAB/Octave
interprets values outside this range as complex numbers. To address this issue, a
script named my_asin was developed. This script accepts a single value x and
checks if it falls within the valid range. If x is outside the range, it triggers a beep
sound and displays an error message. If x is within the allowed range, the script
returns the asin value for the input.