MATLAB projects for Physics 4A students Outline: 1. Project 1 –Graphical method for solving kinematic problems 2. Project 2 – Analyses of acceleration plots 3. Project 3 – Euler method for integrating equations of motion PROJECT 1 Graphical method for solving kinematic problems Sample problem N1: Three friends, Andy, Juan and Sarah, had a bike race. At an instant t=0, Andy was 20 meters ahead of Sarah and Juan was 50 meters ahead of Sarah. Andy was biking with a constant speed 10 m/s. Juan had speed 12 m/s. He was slowing down with acceleration 0.8 m/s2. Sarah was trying to catch up with the boys. At an instant t=0, her speed was 5m/s and her acceleration was 2 m/s2. Plot the graphs of motion of three friends and find at what time Sarah will pass by Andy and Juan and at what distance from the initial position. _____________________________________________________________________________ Sample problem solution: 1. Set the time mesh t = 0:0.1:10 2. Define positions as functions of time x1 = 20+10*t; x2 = 50+12*t-0.4*t.^2/2; x3 = 7*t+2*t.^2/2; 3. Plot the graphs plot(t,x1) hold all plot(t,x2) plot(t,x3) 4. Set properties of the plot set(gca,'XTick',0:2:10) set(gca,'YTick',0:10:100) title('Equations of Motion','FontSize', 18); xlabel('Time, s','FontSize', 18); ylabel('Distance, m','FontSize', 18); grid on Answer: Sarah caught Andy after 6.2 seconds at the distance 80 meters. She caught Juan after 8.8 seconds at the distance 140 meters. The plot: Sample problem N2: In the traffic jam a car started off with acceleration 2 m/s2 and was accelerating for 5 seconds. Then it moved with a constant speed for 3 seconds. Then, the driver pushed delicately the breaks and the car decelerated for 4 seconds. At the end its speed was 4 m/s. Plot the graph of motion of the car. How far did the car go during this time? ___________________________________________________________________________________ Sample problem solution: 1. First we plot the motion of the car during the first 5 seconds: t = 0:0.01:5; x1 = 2*t.^2/2; plot(t,x1) hold all 2. Second period goes from 5 seconds to 8 seconds: t = 5:0.01:8; 3. The car continues its motion starting at the distance 25 meters. Since it starts moving with a constant speed at an instant 5 seconds, the whole graph must be shifted to the right 5 seconds: t>(t-5): x2 = 25+10*(t-5); plot(t,x2) 4. The time period is from 8 to 12 seconds: t = 8:0.01:12; 5. The car continues its motion starting at the distance 55 meters. The graph must be shifted to the right 8 seconds: t->t-8: x3 = 55+10*(t-8)-1.5*(t-8).^2/2; 6. Graph settings: set(gca,'XTick',0:1:10) set(gca,'YTick',0:20:200) title('Equations of Motion','FontSize', 18); xlabel('Time, s','FontSize', 18); ylabel('Distance, m','FontSize', 18); grid on Answer: The car went about 82 meters. Problem to solve independently: Three athletes started 100 meters race. After the start, the athlete N1 was running with acceleration 0.8 m/s2 for 9 seconds, then, he kept running with the constant speed. Athlete number N2 had acceleration 1 m/s2 for 7 seconds than he started to decelerate at a rate 0.2 m/s2. Athlete N3 got to speed 5 m/s extremely quickly and hold this speed all the way. Plot the graphs of motion of three athletes and answer the question: who won the race? PROJECT 2 Studying the dependence of acceleration on different parameters of the system Sample problem N1: A block of mass 0.3 kg lies on the inclined plane with the friction coefficient 0.3. Plot how acceleration depends on the angle of the inclined plane when it changes from 0 °to 90°. In what range the acceleration is negative? Does it correspond to any physical situation? ___________________________________________________________________________________ Sample problem solution: Obtain analytical expression for acceleration: x : mgsin ϕ − fk = ma y : mg cosϕ − N = 0 N = mg cosϕ fk = µ k N = µ k mg cosϕ mgsin ϕ − µ k mg cosϕ = ma a = g(sin ϕ − µ k cosϕ) Set the mesh for the angle and plot the function: tetta = 0:0.01:pi/2 a=9.8*(sin(tetta)-0.3*cos(tetta)) plot(tetta,a) set(gca,'XTick',0.5:0.1:1.2) set(gca,'YTick',0:0.5:8) title('Acceleration as a function of angle','FontSize',18); xlabel('Angle, radians','FontSize', 18); ylabel('Acceleration','FontSize', 18); grid on Answer: Acceleration is negative for the angle varying from 0 to 0.29 radians. In this case the incline of the surface is too small for an object to slide down. Sample problem N2: Two blocks are connected by a string as shown below. The frictionless inclined surface makes an angle 45° with the horizontal. The block on the inclined surface has a mass of 4 kg. Θ=45° Plot the dependence of acceleration of the blocks on the hanging mass. ___________________________________________________________________________________ Sample problem solution: 1. Set number of points, mass range, and the length of the mass step: npoints = 200 mi = 0 mf = 40 dm = mf/npoints 2. Initialize mass vector and acceleration vector: m = zeros(npoints,1) a = zeros(npoints,1) 3. Calculate acceleration for each value of mass: for i = 1:1:npoints; m(i+1) = m(i) + dm a(i+1) = 9.8*(m(i)-4*0.707)/(m(i)+4); end 4. Plot the graph plot(m,a,'b') 5. Graph settings: title('Acceleration as a function of mass','FontSize', 18); xlabel('Mass, kg','FontSize', 18); ylabel('Acceleration, m/s2','FontSize', 18); grid on The plot: Answer: If hanging mass is smaller than 3 kg, the projection of acceleration on y-‐axis will be negative. The mass on the inclined plane will outweigh the hanging mass. If it will be equal to 3 kg, the system will be at rest. If hanging mass is larger than 3 kg, the system will move downward. Problem to solve independently: Consider the following experimental set up: Hanging mass is 7 kg. The mass lying on the plane is 2.5 kg. The plane has some friction. Plot the dependence of acceleration on the friction coefficient. Find and show on the graph at what value of the coefficient the system is at rest. PROJECT 3 Euler method Euler method is an explicit method of integration of differential equation. If one knows initial position and initial velocity of the object, he can find its approximate trajectory by doing step-‐by-‐step integration. Suppose initial position is: x(t 0 ) = x 0 and velocity is given as a function of time and position: x'(t) = f(t, x(t)) One splits time interval into n-‐steps equal to dt. Time interval becomes a vector of n-‐dimension. Then, starting from the initial position, one can find the next value of the function by approximating it with the slope: x n+1 = x n + f(t, x n )dt Going through all the values of time vector, one calculates approximate values of the function that deviate from exact values. Sample problem N1: An acorn falls from 10 meters height starting from rest. Integrate equation of motion of an acorn using Euler’s method making 5 steps, 10 steps and 100 steps of integration. Plot approximate values of y-‐coordinate and exact values. Analyze how accuracy of the method changes if one decreases the number of time-‐steps. Find the time when the acorn hits the ground. ___________________________________________________________________________________ Sample problem solution: Velocity is a function of time 1. Set the number of the time steps, time interval and time step duration: npoints = 5; ti=0; tf=1.5; dt=(tf-ti)/npoints; 2. Initialize time vector, velocity vector and position vector: time = zeros(npoints,1); v = zeros(npoints,1); y = 10*ones(npoints,1); 3. Going through the values of the time vector, we sequentially compute the values of the velocity and position: for step = 1:npoints-1; v(step+1)=v(step)+9.8*dt; y(step+1)=y(step)-v(step)*dt; time(step+1) = time(step) + dt; end 4. We plot the function: plot(time, y,'r' ) hold all 5. We plot the exact function of position on time: yexact=y(1)-9.8*time.^2/2 plot(time,yexact,'black') 6. Plot settings: set(gca,'XTick',0:0.5:2.0,'FontSize', 20) set(gca,'YTick',-4:2:12,'FontSize', 20) title('Equations of Motion','FontSize', 24); xlabel('Time, s','FontSize', 24); ylabel('Distance, m','FontSize', 24); grid on The plot: Answer: The acorn lands after 1.42 seconds. The larger is the number of the time steps, the closer is the graph to the exact equation. Deviation from the graph is due to the fact that we approximated the function with the slope that is just the first derivative. Sample problem N2: (based on 'Computational Physics' book by N. Giordano and H. Nakanishi) Plot the angle of deviation of the pendulum of length 1 m as a function of time. _______________________________________________ Theory: Θ L x mg First, let us find angular velocity of pendulum and show that it is a function of angle. We will use second Newton’s law: F = ma Pendulum has only one coordinate that changes with the time that the angle from the vertical. Acceleration of the pendulum is equal to the angular acceleration: d 2Θ a = mL 2 dt The centripetal force is a projection of the weight on the axis perpendicular to the radius: F = mgsin Θ The equation is: d 2Θ mL 2 = mgsin Θ dt For small deviations of the pendulum sinus function is equal to the value of the argument. We obtain the following dependence of the angular acceleration: d 2Θ g = Θ dt 2 L This expression can be used to approximate angular velocity. ___________________________________________________________________________________ Sample problem solution: 1. Set parameters of the pendulum: L = 1; g = 9.8 npoints = 500; dt = 0.02; 2. Initialize time, angular velocity and angle vectors: time = zeros(npoints,1); omega = zeros(npoints,1); theta = zeros(npoints,1); theta(1)=0.02; 3. Go through all the values of the time vectors and compute angular velocity and angle at each step: for step = 1:npoints-1 omega(step+1) = omega(step) (g/L)*theta(step)*dt; theta(step+1) = theta(step)+omega(step)*dt time(step+1) = time(step) + dt; end 4. Plot the graph: plot(time,theta,'r') grid on hold all 5. Compute angle as an exact function of time: omega_exact=sqrt(g/L) t_exact = theta(1)*cos(omega_exact*time) plot(time, t_exact,'b') 6. Plot settings: set(gca,'XTick',0:1:10.0,'FontSize', 20) set(gca,'YTick',-1:0.05:1,'FontSize', 20) title('Pendulum motion','FontSize', 24); xlabel('Time, s','FontSize', 24); ylabel('Angle, radians','FontSize', 24); grid on The plot: Problem to solve independently: A ball of mass 0.2 kg is attached to the horizontal spring with a spring constant 100 N/m and initially displaced 0.27 m. Integrate equation of motion of the ball and plot it displacement as a function of time. Compare it with the exact solution: x = x 0 cos (ω ⋅ t ) where ω = k m
© Copyright 2024