You are on page 1of 13

MATLAB ACTIVITY

PHY01: General Physics 1


Activity 2

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:

The drawing shows a top view of a frictionless horizontal surface, where


there are two springs with particles of mass m1 and m2 attached to them. Each
spring has a spring constant of 120 N/m. The particles are pulled to the right and
then released from the positions shown in the drawing. How much time passes
before the particles are side by side for the first time at x = 0 m if

Figure 1. Problem Illustration

(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>

%Initialize variables for Part A


k = 120; %spring constant in N/m
m1 = 3; %mass_1 in kg
m2 = m1; %mass_2 in kg
m = m2; %mass
%Display given
fprintf("-------------------------------------------------------")
fprintf("The given values for Part A are:" )
fprintf("k = %0.2f N/m", k)
fprintf("m_1 = %0.2f kg", m1)
fprintf("m_2 = %0.2f kg", m2)
fprintf("-------------------------------------------------------")
%Solve
fprintf("Use the formulae: ")
%Display used formulas
disp(formula1)
disp(formula2)
disp(formula3)
disp(formula4)
disp(formula5)
disp(formula6)
disp(formula7)
%Solve for the Period
T = 2*pi*sqrt(m/k);
%Display answer
fprintf("-------------------------------------------------------")
fprintf("The period in Part A is %0.2f s." , T)
fprintf("-------------------------------------------------------")
fprintf("Use the formula: ")
%Display used formula
disp(formula8)
%Solve for the Time
t = T/4;
%Display answer
fprintf("-------------------------------------------------------")
fprintf("In Part A, both particles would meet at x = 0 side")
fprintf("by side for the first time at approximately %0.2f s.", t)
fprintf("-------------------------------------------------------")

<section break>

%Initialize variables for Part B


K = 120; %spring constant in N/m
m_1 = 3; %mass_1 in kg
m_2 = 27; %mass_2 in kg
%Display given
fprintf("-------------------------------------------------------")
fprintf("The given values for Part B are:")
fprintf("k = %0.2f N/m", K)
fprintf("m_1 = %0.2f kg", m_1)
fprintf("m_2 = %0.2f kg", m_2)
fprintf("-------------------------------------------------------")
%Solve
fprintf("Use the formulae: ")
%Display used formulas
disp(formula9)
disp(formula10)
%Solve for the Period
T_1 = 2*pi*sqrt(m_1/k);
T_2 = 2*pi*sqrt(m_2/k);
%Display answer
fprintf("-------------------------------------------------------")
fprintf("The period of T₁ in Part B is %0.2f s.", T_1)
fprintf("The period of T₂ in Part B is %0.2f s.", T_2)
fprintf("-------------------------------------------------------")
fprintf("It can be noticed that:")
%Display used formulae
disp(formula11)
fprintf("Thus,")
disp(formula12)
disp(formula13)
%Solve for the Time
t_1 = (3*2*pi*sqrt(m_1/k))/4;
t_2 = (2*pi*sqrt(m_2/k))/4;
%Display answer
if t_2 == t_1
T = t_1;
fprintf("-------------------------------------------------------")
fprintf("In Part B, both masses would meet at x = 0 side by")
fprintf("side for the first time at approximately %0.2f s.", T)
fprintf("-------------------------------------------------------")
end

<section break>

%Conclusion for easier viewing of answers


%Display all answers
fprintf("-------------------------------------------------------")
fprintf("Summary of answers:")
fprintf("(a) In Part A, both particles would meet at x = 0 side")
fprintf("by side for the first time at approximately %0.2f s.", t)
fprintf("(b) In Part B, both masses would meet at x = 0 side by")
fprintf("side for the first time at approximately %0.2f s.", T)
fprintf("-------------------------------------------------------")
%end code

<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

You might also like