Professional Documents
Culture Documents
Matlab Sample
Matlab Sample
GROUP # 6
Añasco, Mark Francis A.
Acebuche, Eian Timothy T.
SUBMITTED TO:
Sir Mark Timothy Morillo
DATE:
December 4, 2021
2ND QUARTER
A.Y. 2021 - 2022
BRIEF DESCRIPTION OF THE CODE:
The learners’ objective with the MATLAB code is to create a code that would
solve the given problem. This code would solve the time it would take for the two
particles or masses to meet at x=0 for the first time.
The code has four main parts: variable and equation initialization, Part A, Part B,
and conclusion. As the name implies, variable and equation initialization was where the
code initialized all needed variables and equations. Subsequently, Part A solves the
problem’s first part, where m1 and m2 have the same mass of 3 kg. Furthermore, the
time it took for the two particles or masses to meet at x = 0 for the first time was
calculated here. Then, Part B solves the problem’s second part, where m1 and m2 have
their respective masses of 3 kg and 27 kg. Likewise, the time it took for the two particles
or masses to meet at x = 0 for the first time was also determined here. Finally, the
conclusion summarizes all the answers to the given question’s problems.
The code utilized thirteen formulae (see Equations 1 to 13 below). Equations 1 to
8 were for Part A. In Part A, Equations 1, 2, and 3 were for the equivalent masses,
Equations 4, 5, and 6 were for the equivalent periods, Equation 7 was for the period in
Part A, and Equation 8 was for the time in Part A. On the other hand, Equations 9 to 13
were for Part B. In Part B, Equation 9 was for Period 1 in Part B, Equation 10 was for
Period 2 in Part B, Equation 11 was for the equivalent periods in Part B, Equation 12
was for the time in Part B, and Equation 13 was an alternative formula to Equation 12.
𝑚1 = 𝑚2 𝑚 = 𝑚1 𝑚 = 𝑚2
Equation 1. Equivalent Equation 2. Mass 1 Equation 3. Mass 2
Masses in Part A
𝑇1 = 𝑇2 𝑇 = 𝑇1 𝑇 = 𝑇2
Equation 4. Equivalent Equation 5. Period 1 Equation 6. Period 2
Periods in Part A
𝑇
𝑇 = 2π
𝑚 𝑡 = 4
𝑚1
𝑘 𝑇1 = 2π 𝑘
Equation 7. Period in Part Equation 8. Time in Part A
Equation 9. Period 1 in
A Part B
𝑇2 = 3𝑇1 3𝑇1
𝑚2
𝑇2 = 2π 𝑡 = 4
𝑘 Equation 11. Equivalent Equation 12. Time in Part
Equation 10. Period 2 in Periods in Part B
Part B B
𝑇2
𝑡 = 4
Equation 13. Alternative
Time in Part B
The code contained functions such as fprintf, disp, and if. The function fprintf
showed the answers computed from the entered code, disp displayed the formulae
utilized, and the if value was used to ensure that Equations 12 and 13 were equivalent
at the end. Furthermore, the code declared variables to represent the given values. The
variables with m represented mass, the variable k symbolized the spring constant, the
variables with T represented period, and the variable t symbolized time.
In the end, the code solved the given problem and calculated the correct answer
for Parts A and B. In Part A, the learners determined that the time it would take for the
two particles or masses to meet at x = 0, side by side, was approximately 0.25 s. Finally,
they also calculated that the time it would take for the two particles or masses to meet at
x = 0, side by side, in Part B was approximately 0.75 s.
PROBLEM:
(a) m1 = m2 = 3.0 kg and (b) m1 = 3.0 kg and m2 = 27 kg? (Cutnell et al., 2018,
p. 287)
SOLUTION:
Figure 2. Solution
CODE:
clear
clc
%solve (a)
%initiate variables and formula sets for visual purposes
syms ('T','T_1','T_2','m','m_1','m_2','k','t')
formula1 = m_1 == m_2;
formula2 = m == m_1;
formula3 = m == m_2;
formula4 = T_1 == T_2;
formula5 = T == T_1;
formula6 = T == T_2;
formula7 = T == 2*pi*sqrt(m/k);
formula8 = t == (1/4)*T;
formula9 = T_1 == 2*pi*sqrt(m_1/k);
formula10 = T_2 == 2*pi*sqrt(m_2/k);
formula11 = T_2 == 3*T_1;
formula12 = t == (3/4)*T_1;
formula13 = t == (1/4)*T_2;
<section break>
<section break>
<section break>
<code end>
SCREENSHOT:
SCREENSHOT 1
SCREENSHOT 2
SCREENSHOT 3A
SCREENSHOT 3B
SCREENSHOT 4A
SCREENSHOT 4B
SCREENSHOT 5A
SCREENSHOT 5B
SCREENSHOT 6A
SCREENSHOT 6B
SCREENSHOT 7A
SCREENSHOT 7B
REFERENCE:
Cutnell, J. D., Johnson, K. W., Young, D., & Stadler, S. (2018). Physics (11th ed.). Wiley
Global Education US. https://wileyplus.vitalsource.com/books/9781119326342