Sunteți pe pagina 1din 20

Atienza, Marvin James A.

Talag, Misael, M.

Experiment #1: Programming in MATLAB and Applications


I. OBJECTIVES
This experiment will help the students to develop the basic understanding of numerical
algorithms and skills to implement algorithms and flowchart to solve mathematical problems on
the computer. Moreover, Observe the importance of computers in the implementation and
development of numerical methods. Specifically, it aims to:

1. Compute the analytical solution using conventional or manual solutions.


2. Create MATLAB programs that will solve the given problem.
3. Create algorithms and flowchart to solve the given problem.

II. DISCUSSION
Numerical Methods are techniques by which mathematical problems are formulated so
that they can be solved with arithmetic and logical operations.

A computer program (code) is a sequence of computer commands. It is a set (list) of


commands (operations) that are to be executed by the computer. Commands can be grouped
into several categories such as:

– Commands for input and output of data.


– Commands for defining the variables.
– Commands that execute the mathematical operations.
– Commands that control the order in which commands are executed and enable the
computer to choose different groups of commands to be executed under different
circumstances.
– Commands that enable the computer to repeat sections of the programs. – Commands
that create figures and graphical displays of the results.

A flowchart is a visual or graphical representation of an algorithm.

Algorithm is a step – by – step instructions on how to carry out the solutions.

III. SOFTWARE NEEDED


ITEM NO. DESCRIPTION QUANTITY
MATLAB 1

IV. METHODOLOGY
a. Solve the Analytical Solution:
1. Four circles are placed as shown in the figure. At each point where two circles are in
contact, they are tangent to each other. Determine the distance between the centers
C2 and C4. The radii of the circles are: R1 = 16mm, R2 = 6.5mm, R3 = 12mm, and R4 =
9.5mm.

2. The tank in a water tower has the geometry shown in the figure (the lower part is a
cylinder and the upper part is an inverted frustum of a cone). Inside the tank there is
a float that indicates the level of the water. Write a MATLAB program that
determines the volume of the water in the tank from the position (height h) of the
float. The program asks the user to enter a value of h in m, and as output displays the
volume (V)of the water in m3.

Note:

• For 0 ≤ h ≤19 m the volume of the water is given by the volume of a cylinder with
height h: V = π12.52h.
• For 19 < h ≤ 33m the volume of the water is given by adding the volume of a
cylinder with h = 19 m, and the volume of the water in the cone:

V = π12.52 * 19 + π/3(h -19)*(12.52 + 12.5 * rh + rh2) Where:

rh = 12.5 + 10.5/14(h -19)

3. An object with an initial temperature of T0 that is placed at time t = 0 inside a


chamber that has a constant temperature of Ts will experience a temperature change
according to the equation:

T = Ts +(T0 - Ts)e -kt


where T the temperature of the object at time t, and k is a constant. A soda can at a
temperature of 120° F (after being left in the car) is placed inside a refrigerator
where the temperature is 38°F. Determine, to the nearest degree, the temperature
of the can after three hours. Assume k = 0.45.

4. The balance B of a savings account after t years when a principal P is invested at an


annual interest rate r and the interest is compounded n times a year is given by:

If the interest is compounded yearly, the balance is given by:

Suppose $5,000 is invested for 17 years in one account for which the interest is
compounded yearly. In addition, $5,000 is invested in a second account in which the
interest is compounded monthly. In both accounts the interest rate is 8.5%.
Determine how long (in years and months) it would take for the balance in the
second account to be the same as the balance of the first account after 17 years.

b. Flowchart:
Create flowchart for each problem to find the unknown parameters. You may
use any if statement (if-end, if -else-end, and if -elseif -else-end) if applicable.

c. Algorithm:
Create an algorithm for each problem to find the unknown parameters. Use all
command categories if applicable.

d. Script File:
Write a MATLAB program that determines the unknown parameters for each
problem. The program should ask the user to enter all the input variables and will
output displays for the computed parameters.
Output:
Problem #1
A. Analytical Solution

Solution:
If h <19, total volume is
𝑉𝐶𝑜𝑛𝑒 = 𝜋(12.5)2 (ℎ)
If 19<h≤33, total volume is
𝑉𝑇𝑜𝑡𝑎𝑙 = 𝑉𝐶𝑜𝑛𝑒 + 𝑉𝑓𝑟𝑢𝑠𝑡𝑢𝑚
Where,
𝜋(ℎ − 19)
𝑉𝑓𝑟𝑢𝑠𝑡𝑢𝑚 = (12.52 + 12.5𝑟ℎ + 𝑟ℎ 2 )
3
𝑉𝐶𝑜𝑛𝑒 = 𝜋(12.5)2 (19)
10.5
𝑟ℎ = 12.5 + (ℎ − 19)
14
Then,
𝜋(ℎ − 19)
𝑉𝑇𝑜𝑡𝑎𝑙 = 𝜋𝑟 2 (19) + (12.52 + 12.5𝑟ℎ + 𝑟ℎ 2 )
3
B.Algorithm:
1. Begin
2. Initialized variables h (height of the cylinder), r(radii) and f (frustum of the cone).
3. Assign the values of h, r, and f.
4. Input the value of the position of the float (in meters).
5. If h<=19, 𝑉𝑇 = 𝜋(12.5)2 ℎ.
10.5
6. Else if 19<h≤33, 𝑟ℎ = 12.5 + (ℎ − 19);
14
7. Else, height can’t exceed 33 meters
𝜋(ℎ−19)
8. 𝑉𝑇 = 𝜋(12.5)2 (19) + (12.52 + 12.5𝑟ℎ + 𝑟ℎ 2 ).
3
9. Output 𝑉𝑇 .
10. End

C. Flowchart
D. Editor Window

Command Window
Problem #2
A. Analytical Solution

Analytical Solution:
𝑅1 = 16𝑚𝑚
𝑅2 = 6.5𝑚𝑚
𝑅3 = 12𝑚𝑚
𝑅4 = 9.5𝑚𝑚
Solving for the Lengths of the Sides,
(𝐶1 𝐶2 ) = 𝑅1 + 𝑅2 (𝐶2 𝐶3 ) = 𝑅2 + 𝑅3
(𝐶1 𝐶2 ) = 16 + 6.5 = 22.5𝑚𝑚 (𝐶2 𝐶3 ) = 6.5 + 12 = 18.5𝑚𝑚
(𝐶1 𝐶3 ) = 𝑅1 + 𝑅3 (𝐶3 𝐶4 ) = 𝑅3 + 𝑅4
(𝐶1 𝐶3 ) = 16 + 12 = 28𝑚𝑚 (𝐶3 𝐶4 ) = 12 + 9.5 = 21.5𝑚𝑚
(𝐶1 𝐶4 ) = 𝑅1 + 𝑅4
(𝐶1 𝐶4 ) = 16 + 9.5 = 25.5
Mathematical Model:
Using Cosine Law,
𝑐 2 = 𝑎2 + 𝑏 2 − 2𝑎𝑏 cos(𝑐)
Solving for ∅1 ,

(𝐶2 𝐶3 )2 = (𝐶1 𝐶2 )2 + (𝐶1 𝐶3 )2 − 2(𝐶1 𝐶2 )(𝐶1 𝐶3 ) cos ∅1

(𝐶1 𝐶2 )2 + (𝐶1 𝐶3 )2 − (𝐶2 𝐶3 )2


∅1 = cos −1
2(𝐶1 𝐶2 )(𝐶1 𝐶3 )
(22.5)2 + (28)2 − (18.5)2
∅1 = cos −1 = 41.2030
2(22.5)(28)
Solving for ∅2 ,

−1
(𝐶1 𝐶3 )2 + (𝐶1 𝐶4 )2 − (𝐶3 𝐶4 )2
∅2 = cos
2(𝐶1 𝐶3 )(𝐶1 𝐶4 )

(28)2 + (25.5)2 − (21.5)2


∅2 = cos −1 = 44.1038
2(28)(25.5)
Solving for ∅3 ,
∅3 = ∅1 + ∅2
∅3 = 41.2030 + 44.1038 = 88.3068
Solving for 𝐶2 𝐶4,

(𝐶2 𝐶4 ) = √(𝐶1 𝐶2 )2 + (𝐶1 𝐶4 )2 − 2(𝐶1 𝐶2 )(𝐶1 𝐶4 ) cos ∅3

(𝐶2 𝐶4 ) = √(22.5)2 + (25.5)2 − 2(22.5)(25.5) cos 88.3068

(𝐶2 𝐶4 ) = 33.5051𝑚𝑚

𝑨𝒏𝒔𝒘𝒆𝒓: 𝑻𝒉𝒆 𝒅𝒊𝒔𝒕𝒂𝒏𝒄𝒆 𝒃𝒆𝒕𝒘𝒆𝒆𝒏 𝒕𝒉𝒆 𝒄𝒆𝒏𝒕𝒆𝒓𝒔 𝑪𝟐 𝒂𝒏𝒅 𝑪𝟒 𝒊𝒔 𝟑𝟑. 𝟓𝟎𝟓𝟏𝒎𝒎.

B. Algorithm:
1. Start
2. Initialize variables R1, R2, R3, R4
3. Assign given values to R1, R2, R3, R4
4. Calculate the lengths of the sides
5. Store lengths of the sides
6. Calculate ∅1 , ∅2 , ∅3
7. Store ∅1 , ∅2 , ∅3

8. Calculate 𝐶2 𝐶4
9. Display 𝐶2 𝐶4
10. End
C. Flowchart
D. Editor Window

Command Window
Problem #3

A. Analytical Solution

Equation 1

Mathematical Model:
𝑇 = 𝑇𝑠 + (𝑇0 − 𝑇𝑠 )𝑒 −𝑘𝑡
Equation 2
Where:
T= Temperature of the object at time t
Ts= Constant temperature of chamber (38°F)
T0= Initial temperature of object (120°F)
k= constant (0.45)
t= time elapsed (3 hours)

Solution
𝑇 = 𝑇𝑠 + (𝑇0 − 𝑇𝑠 )𝑒 −𝑘𝑡
𝑇 = 38°𝐹 + (120°𝐹 − 38°𝐹)𝑒 −0.45(3ℎ𝑜𝑢𝑟𝑠)
𝑇 = 59.2577° 𝐹

Answer: 59.2577° 𝐹

B. Algorithm:
1. Start
2. Initialize variables T, Ts, T0, k, t
3. Assign given values to Ts, T0, k, t
4. Calculate 𝑇 = 𝑇𝑠 + (𝑇0 − 𝑇𝑠 )𝑒 −𝑘𝑡
5. Display T
6. End

C. Flow Chart
D.Editor Window

Command Window
Problem #4

A. Analytical Solution

Equation 1

Mathematical Model:
𝑟
𝐵 = 𝑃 (1 + )𝑛𝑡
𝑛
Equation 2
𝐵 = 𝑃 (1 + 𝑟)𝑡
Equation 3
Where:
B= Balance of a saving Account ( $)
P= Principal Invested (5000 $)
r= Interest rate (8.5 %)
t= time in years (17 years)
n= number of times compounded in a year (Monthly for second account; Annually for fist
account)
Solution
𝐵 = 𝑃 (1 + 𝑟)𝑡
Solve for B in Equation 3

𝐵 = 5000 (1 + 0.085)17
𝐵 = $ 20011.31155
Solving for t in Equation 2
𝑟
𝐵 = 𝑃 (1 + )𝑛𝑡
𝑛
𝐵
log(𝑃 )
𝑡= 𝑟
𝑛𝑙𝑜𝑔(1 + 𝑛)

20011.31155
log( )
𝑡= 5000
0.085
12𝑙𝑜𝑔(1 + 12 )

𝑡 = 16.37371524
𝑡𝑦𝑒𝑎𝑟𝑠 = 16

𝑡𝑚𝑜𝑛𝑡ℎ𝑠 = 0.37371524(12)
𝑡𝑚𝑜𝑛𝑡ℎ𝑠 = 4.48 𝑚𝑜𝑛𝑡ℎ𝑠 ≈ 5 𝑚𝑜𝑛𝑡ℎ𝑠

Answer: 16 𝑦𝑒𝑎𝑟𝑠 𝑎𝑛𝑑 4.48 𝑚𝑜𝑛𝑡ℎ𝑠 𝑜𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒𝑙𝑦 16 𝑦𝑒𝑎𝑟𝑠 𝑎𝑛𝑑 5 𝑚𝑜𝑛𝑡ℎ𝑠

B. Algorithm:
1. Start
2. Initialize variables B, P, r, t, n
3. Assign given values to P, r, t, n
4. Calculate 𝐵 = 𝑃 (1 + 𝑟)𝑡
5. Store B
𝐵
log( )
𝑃
6. Calculate 𝑡 = 𝑟
𝑛𝑙𝑜𝑔(1+ )
𝑛

7. tyears = integer part of t


8. tmonths = decimal part of t * 12
9. Display t(years) and t(months).
10. End
C. Flowchart
D.
Editor Window

Command Window
QUESTIONS:
A. Evaluate the following expressions using MATLAB

a.
b.

c.
d.

B. GIVEN A=-2, B=3, C=5


a.
b.
c.

d.
C. GIVEN v=[4 -1 2 3 1 -2 5 0] and u=[5 -1 0 3 -3 2 1 5]
a.

b.

c.
d.

Conclusion:
After doing the Laboratory Experiment, it could be concluded that using MATLAB and the
applicable techniques, the group was able to perform the tasks needed. The group was able to
compute for the analytical solution using both the conventional and manual solutions, while also
utilizing MATLAB as a way of making the process easier. The group was also able to create the
corresponding MATLAB programs which would show the needed values and implement the
needed outputs.

S-ar putea să vă placă și