Test 1
Test 1
Roll No IV.ChE-1
Name Kaung Htet Wai
Major Chemical Engineering
Date 23.1.2025
Problem No Marks
I (Quiz)
1
2
3
4
5
6
Total Marks
Yangon Technological University
Department of Mechanical Engineering
Computer Application in Engineering (ME 41019)
Test I
1. Perform the following statements in the command windows and present the outputs
from command windows.
(a) Calculate:
sin(0.2 π)
(i) + tan72 °
cos(π /6)
2
(ii) ( tan64 ° cos 15° ) + sin 237 °
cos 20 °
(b) Two trigonometric identities are given by:
(iii) cos 2 x−sin 2 x=1−sin2 x
tan x 1
(iv) =
sin x−2 tan x cos x −2
For each part, verify that the identity is correct by calculating the values of the
left and right sides of the equation, substituting x = π/10
(c) Create the following three row vectors: a=[5 8 -1 0 2], b=[4 1 9 -2 3], and
c=[-3 5 0 6 1].
(v) Use the three vectors in a MATLAB command to create a
nine-element row vector consisting from the first three
elements of the vectors a, b, and c, respectively (i.e., 5 8 -1
4 1 9 -3 5 0).
(vi) Use the three vectors in a MATLAB command to create a
nine-element column vector consisting from the last
three elements of the vectors a, b, and c, respectively.
(d)Using the zeros, ones, and eye commands, create the following
arrays by typing one command:
[ ] [ ]
1 0 01 0 0 1001
(vii) A= 0 1 0 01 0
0 0 1 0 01
B=
0 0 01 1 [
0 0 01 1 C=
]
1000
1000
(20 Marks)
Page 1 of 4
Page 2 of 4
2. A food company manufactures five types of 8-oz trail mix packages using different
mixtures of peanuts, almonds, walnuts, raisins, and M&Ms. The mixtures have the
following compositions:
4. Create an array of 100 input samples in the range 1 to 100 using the linspace function,
and plot the equation
y(x) = 20 log10(2x)
on a semilogx plot. Draw a solid blue line of width 2, and label each point with a red
circle. Now create an array of 100 input samples in the range 1 to 100 using the
logspace function, and plot Equation on a semilogx plot. Draw a solid dash line of
width 2, and label each point with a black star. Be sure to include a title and axis
labels, and include the equation for the function being plotted in the title string.
(Note that you will need stream modifiers to get the italics and the superscripts in the
title string.) Save the Figure as png or jpeg format.
(20 Marks)
Page 3 of 4
Write a program (using a loop) that determines for a given number of terms n . Run
the program with n = 10, n = 100, and n = 1,000. Compare the result with pi. (Use
format long.)
(10 Marks)
6. Fibonacci Numbers The nth Fibonacci number is defined by the following recursive
equations:
f (1) = 1
f (2) = 1
f (n) = f (n – 1) + f (n – 2) if n < 2
Therefore, f (3) = f (2) + f (1) = 2+1=3, and so forth for higher numbers. Write an M-
file to calculate and write out the nth Fibonacci number for n > 2, where n is input by
the user. Use a while loop to perform the calculation. Show the results for n = 1:10
using for loop.
Follow the steps of the program design process to produce reliable, understandable
MATLAB programs.
1. State the problem,
2. Define the inputs and outputs,
3. Design the algorithm
4. Turn the algorithm into MATLAB statements.
5. Testing with the program with various input.
Page 4 of 4
Some useful MATLAB Stream Modifier
Page 5 of 4
1.(a) and 1.(b)
Page 6 of 4
1.(d)(i) and 1.(d)(ii)
1.(e)(iii)
Page 7 of 4
2.
Page 8 of 4
3.
5.
Page 9 of 4
6.
1. State the problem
Outputs:
1. Prompt the user for the car type, rental duration, and miles driven.
2. Determine the daily rate, free miles, and cost per additional mile based on the rental
duration and car type using conditional logic.
3. Calculate the total rental cost:
Page 10 of 4
o Determine whether miles exceed the free mileage allowance for the rental
period.
o Add the daily rate cost and any additional mileage cost.
4. Display the total cost.
Page 11 of 4
Page 12 of 4
4.
Page 13 of 4
Page 14 of 4