NORTH WEST UNIVERSITY (Mafikeng Campus) Physics Department First Year Physics Laboratory Manual NPHY 111 2019 COMPILED BY PROF. R. MEDUPE MR. M.D. NHLAPO Introduction This manual was created from an older manual of the department of Physics. We wish to acknowledge the author(s) of the older manual, in particular Prof. S. Taole, who has kindly edited this new one. Thanks also to Mr. Moses Molefe, the lab technician for his advise and assisting us in testing the equipments. NOTE: • Each of you should have a real experience with each of the six experiments that are planned for this semester. Hence you will be divided into groups that meet at different days of the week between 14:00 and 17:00. • The main focus is going to be learning how to analyze data using computer methods. • All reports must be written using openOffice word processor, with your name clearly written, and those of your group members in your cover page. • All graphs to be drawn on MATLAB, saved as JPG file and inserted into your document. 1 Laboratory Rules NO EATING OR DRINKING IN THE LAB DO NOT THROW TISSUE PAPER ON THE FLOOR/ANYWHERE EXCEPT YOUR DUSTBIN DO NOT TOUCH OR USE ANYTHING IN THE LAB WITHOUT SUPERVISION REPORT ANY MALFUNCTION OR PROBLEMS WITH EQUIPMENTS OR DEVICES TO YOUR SUPERVISOR TAKE PRECAUTION DURING ANY ACTIVITY IN THE LAB 2 Writing a report • You are all provided with a copy of a laboratory report guide (see Appendix C.1). Have a look at it, and follow it when writing your own report. Critical things in a report: - It must be written in your own words, no copying, no plagiarism! - Tables and graphs must have titles (captions) - Measurements of a quantity must always have a unit!! Experiments List The first few weeks of lab sessions will be used to introduce students to the computing facilities that they will use for the experiments. There will be extenzive lecture on uncertainties and significant figures. Students will then be ready to perform the following experiments: • Motion down an inclined plane • Measuring spring constant: Hooke’s Law • Measuring the moment of inertia of a flywheel • Measuring acceleration due to gravity (using PHYWE experiments) • The period and length of a pendulum Assistants There will be four assistants present at each laboratory session. An email address of an assistant to whom you must submit your report will be written on the white board during each lab session. NOTE: Each student submits his/her report to a designated assistant for the day. 3 EXPERIMENT 1 Motion down an inclined plane Aim To investigate the acceleration of a body down a frictionless inclined plane. Apparatus • V-shaped track • Ball-bearing • Counter/timer • Meter-ruler Figure 1: A picture showing the apparatus mentioned above (courtesy of Olebogeng Medupe). 4 Introduction Straight line graphs are convenient because: • They can be easily verified, • It is easy to find the best fit straight line, and • Physical quantities may often be determined from the slope and or intercepts. If we know (or suspect) the form of non-linear relationship we may be able to choose our variables in such a way that the resulting graph is a straight line. For example if our relationship is of the form: y = ax2 + bx a graph of y vs x will not be a straight line but a graph of (1) y x vs x will be (with a slope of a and intercept of b). We can then obtain the unknowns from the slope and the intercept of the graph. Graphs are often used this way in the analyzing of the data. Apart from their use in this manner, graphs have an added advantage of providing a visual representation of one’s data, making it much easier to understand. It is also much easier to see the form of a relationship from a graph than it is from a collection of data in a table. In this practical you will learn how to draw graphs with MATLAB and how to extract the desired quantities. 5 Theory If a ball-bearing is allowed to slide down a frictionless V-shaped track inclined at an angle θ to the horizontal, it is accelerated by the component of the acceleration due to gravity g, down the incline, viz. a = gsinθ (2) The ball-bearing therefore moves with constant acceleration a, in a straight line and its displacement after a time interval, t is given by: 1 x − x0 = v0 t + at2 2 (3) where v0 is the (initial) velocity at the beginning of the interval. Method You are provided with a timer, an V-shaped track and a ruler. An accurate timer is connected to the V-shaped track by three trigger wires. One trigger wire is attached to the top end of the V-shaped track, and that grounds the timer. The other two wires (A and B) will trigger the timer to start, and the other wire stops the timer. A ball-bearing needs to touch both the track and the wire in order to activate the timer. The track is inclined by the V-shaped piece of wood a distance h from the ground. Mark a point on the track some distance away from the trigger wire A that triggers the timer. Always roll the ball-bearing from this marked point. Keep wire A fixed (do not move it). To change the distance between the two wires just move wire B and not wire A. To perform the experiment do the following: • Use a ruler to measure a distance between wires A and B. • Roll the ball-bearing from the marked point, when it passes wire A, the time will be activated. When the ball reaches wire B, the timer stops. 6 • For the measured distance between A and B, take three measurements of the time and ensure that the time measurements are similar (i.e they do not differ by a large amount). Also ensure that you roll the ball-bearing in the same way (i.e. from rest) in order to ensure that v0 is constant. Tabulate the distance between A and B and the measured time. • Do the above procedure for ten distances between A and B and fill in a Table below. x (cm) x (m) t1 (s) t2 (s) t3 (s) tavg (s) Table 1: A table for recording experimental measurements. Write a MATLAB program to plot a graph of x, the distance between the triggers (A and B), versus t, the time taken to travel between the gates. You should find that the relationship x and t is non-linear. This is to be expected for the reason mentioned earlier. Include this plot in your report, and make a comment on it. If however, we set x0 = 0, and divide Eq. 3 through by t, we obtain x 1 = v0 + at t 2 and thus a graph of x t vs t should be a straight line of slope (4) a 2 and intercept v0 . Use the MATLAB program fit.m that is provided (see Appendix E.1) to plot such a graph. And use it to determine the value of a and its uncertainty and the velocity of the glider as it passed the trigger wire A. • How does your measured value of a compare with that predicted by Eq. 2?, assume g = 9.8 m/s2 and use protractor to measure angle θ. • If they do not agree can you explain why this may be so? • What is the value of the initial velocity v0 and its uncertainty? 7 EXPERIMENT 2 Hooke’s law Aim To determine a spring-constant (k). This will be done through investigating Hookes law by attaching weights to a spring and observing how the displacement of the spring changes with the number of weights attached to the spring. Each weight has a mass of 100 grams. The force diagram is shown in Fig. 2 below. Figure 2: A diagram that shows the relationship between the restoring force and the weight of the mass m. Taken from http://en.wikipedia.org/wiki/Hooke’s law. Introduction and Theory Hooke’s law states that the extension of a spring is directly proportional to the load applied to the spring. In mathematical form, the Hooke’s law is expressed as: F = −kx (5) Where F is the restoring force that tends to push the spring back to its equilibrium point, k is the spring constant, and x is the displacement (or extension of the spring). The negative sign in the above equation indicates that the restoring force always acts in a direction opposite that of the displacement. 8 Method You are provided with five copper weights, each measuring 100g. You are also provided with a metre ruler, a spring and a wire hook. Attach the end of the spring to the stand, and fix a wire hook to the other end of the spring. The purpose of the wire hook is to act as a platform on which to attach copper weights. By attaching several weights to the wire hook you increase the weight of the load attached to the spring, and thus alter the restoring force. Mark the rest position of the wire hook attached to the spring. This is your zero displacement (extension) position. Include this position in the table of measured values. You are provided with five copper weights, attached the first one to the metal hook (which is attached to the spring), and note the displacement (you can mark with a pencil and use a ruler afterwards to measure the distance from zero displacement). Keep on adding the copper weights until all of them are attached to the spring, each time mark their respective displacement. You should by now have six measurement of the displacement (starting from zero), and six readings of the cumulative weight of the copper weights. Tabulate your measurement (taking note of significant figures and the rules we discussed last week) as shown below in table 2: Displacement Displacement Mass suspended (cm) (m) (kg) Weight Restoring (N) Force (N) Table 2: A table of measured displacement and the restoring force on the spring. You are provided with a MATLAB program called fit.m (see Appendix E.1). Your practical lecturer will explain to you how to use the program to fit a straight line to the data above (restoring force vs. displacement). Compare the fitting function of the 9 form: F(x) = mx + c (6) With Eq. 5, and use the slope obtained from the fitting function (and the error in the slope) to write down the spring constant. Please remember that it is always important to write down the units of each measurement. Answer the following in your report: • Is your data nicely described by Eq. 5 above? If not, what is the reason for the discrepancy. • What is the value of the spring constant and its error, use the standard scientific way of presenting a measurement and its error. 10 EXPERIMENT 3 Moment of inertia of a Flywheel Aim To determine the moment of inertia (I) of a flywheel from the conservation of energy principle. Apparatus You will need the following apparatus: • A flywheel mounted on the wall, in all the physics laboratories • A string that can be fixed to the axle of a flywheel • Pieces of 100g weights • A wire hanger for attaching weights to the string. • A stop watch • A metre ruler • Vernier Calliper • Triple beam balance 11 Figure 3: A picture of the flywheel with a string attached to the axle, the stop watch. (courtesy of Olebogeng Medupe). Figure 4: A picture of the Vernier Calliper, the weights, string and a metre ruler. (courtesy of Olebogeng Medupe). 12 Introduction and Theory A flywheel is a mechanical device that is used to store rotational energy. It consist of a disk with an axle. The flywheel rotates around the axle (see Fig.3). When a string is wound around the axle, the whole flywheel has a stored potential energy. When the pieces of mass are attached to the string, their weight acts as a torque on the axle and causes the flywheel to start rotating as the mass falls. As the mass (m) drops to the ground from a certain height h, the original gravitational potential energy EP is converted to kinetic energy EK , kinetic energy ER of the flywheel and the work done against frictional force EF acting in the bearing that support the flywheel. Expressions for these types of energy are: EP = mgh (7) 1 EK = mv2 2 (8) 1 ER = Iω 2 2 (9) where I is the moment of inertia and ω is the rotational speed of the flywheel, it is related to speed v in the following way: v = rω (10) where r is the radius of the axle. Conservation of energy implies that the original energy must equal the final energy, hence at height h: 1 1 mgh = mv2 + Iω 2 + EF 2 2 (11) To determine the work done against friction, let us denote the work done against friction over one rotation of the flywheel as Wf . Then for n rotations, the total work done against friction is nWf . If the string is wound (or wrapped around the axle) n times in such 13 a way that after n flywheel rotations, the mass m has reached the ground, then after reaching the ground, the above equation 11 becomes: 1 1 mgh = mv2 + Iω 2 + nWf 2 2 (12) To get and expression for Wf we note that even after the mass has fallen to the ground, the flywheel will continue rotating, it will eventually be stopped by friction. Just before this happens, all the flywheel kinetic energy will have been converted to work done against friction. If it took N flywheel rotations before it stops, then: 1 NWf = Iω 2 2 (13) 1 2 Iω 2N (14) Therefore, Wf = If we substitute equation 14 into equation 12 we get 1 1 n1 2 mgh = mv2 + Iω 2 + Iω 2 2 N2 (15) where n is the number of windings on the string of an axle, N is the number of rotations of the flywheel after mass has detached, but before a flywheel stops, I is the moment of inertia of the flywheel and h is the height from which the mass drops. Equation 15 is the one we will use in our experiment. It can also be written as: 1 1 n1 2 mgh = Iω 2 + mr2 ω 2 + Iω 2 2 N2 (16) and re-arranged to become I n ω2 m= 1+ 2 N gh − 1 r2 ω 2 2 (17) Exercise: Show that equation 17 can be written as I n 1 m= 2 1+ r N 2gh − 1 r2 ω 2 14 (18) You will note that the ratio EP 2gh = 2 2 EK rω (19) is the ratio of gravitational potential energy to kinetic energy (show this in your report). This ratio will be much greater than 1 (i.e. EP EK >> 1) because after the mass has fallen to the ground all the gravitational potential energy would have been shared between the kinetic energy and work done against friction. Therefore we can neglect 1 in the denominator of equation (18), then it becomes: m≈ I n r2 ω 2 1 + r2 N 2gh (20) Thus, we wish to use equation 20 to find a relationship between the mass attached to the string that is wound around the axle, and the time it takes for the mass to fall to the ground. Note that since the acceleration of the falling mass is constant, and it falls from rest, then the distance, h, the mass has fallen is related to distance as: 1 h = at2 2 (21) v = at (22) h t (23) and Hence v=2 If we substitute equation 23 into 20 we get: n 2h 1 m=I 1+ N r2 g t2 (24) Method Please make sure that before you come to the laboratory to perform this experiment you have done the above exercise, as you will be expected to include it in your write-up 15 of the report. Perform the following: 1. Spin the flywheel by hand for atleast five minutes in order to warm the bearings. If this is not done, the friction couple will not remain constant during the experiment. 2. Measure the diameter of the axle of the flywheel using the vernier caliper, calculate the radius r from this. Include this in your report. 3. Measure the weight of the wire hanger using a triple beam-balance and also note it down. 4. You will be provided with a string of a length such that it becomes detached when the weight hits the floor. There is a little notch on the axle that is used as a hook to wind the string around the axle. Attach the wire hanger to the bottom end of the string. Wind the string around the axle until the bottom part of the attached hanger is at a height of 1 meter. Put three 100g mass piece to the hanger. 5. Count the number of windings on the axle, this is n. 6. When you are ready to start counting time, release the mass and the flywheel and immediately start the timer. Stop the timer when the mass has dropped to the ground. Record the time. While doing this, your lab partner should be counting the number of rotations that the flywheel makes from when it started spinning until it stops, this is N. Repeat the same procedure, each time adding 100g piece mass to the hanger. Do this until you have 1000 grams on the hanger. Tabulate your measurements in Table 3 7. Plot the 1 t2 vs mass graph and make a straight-line fit using the MATLAB program fit.m that you have been provided with (see Appendix E.1). 2. The slope of this graph should equal to 16 Mass (grams) Mass (kg) Time taken to fall (seconds) n N Table 3: Tabulation of the data obtained as described in the procedure. n 2h I 1+ N r2 g (25) Hence, determine the moment of inertia and its error. Things to consider: 1. Does n N depend on the mass? To establish this, plot n N vs mass. If so, does it affect your results? 2. Is the assumption EP EK >> 1 justified? Use simple calculations to give an answer. Reference • Haliday, D., Resnick, R., Walker, J., Fundamentals of Physics, 9th Edition. • http://amrita.vlab.co.in/?sub=1&brch=74&sim=571&cnt=1 • Taole, S., Laboratory Manual, Second year, Dept of Physics, NWU, Mahikeng Campus 17 EXPERIMENT 4 Measuring gravitational acceleration from the fall of a ball-bearing Aim The aim of this experiment is to measure the gravitaional constant (g) by studying the motion of a ball-bearing falling vertically under gravity. Apparatus You are provided with the following apparatus: • A digital timer • Ball-bearing • A stand • A release mechanism mounted on the stand • A landing pad 18 Figure 5: The experimental setup Pictures (courtesy of D. Nhlapo). Figure 6: A pictures of a release mechanism which shows a release knob and clamping nut (courtesy of D. Nhlapo). 19 Introduction and Theory The motion of an object falling under gravity is described by Newton’s second law: F = ma. The height from which the falling object is released is related to the time it takes to fall by: 1 h = v0 t + gt2 2 (26) where v0 is the initial speed of the object and g is the gravitational constant. If the object falls from rest, when v0 is zero and equation 26 becomes: 1 h = gt2 2 (27) Therefore, the bigger the height, the longer is the time an object will take to fall to the ground. Equation 27 can be used to determine the value of g by investigating the relationship between height (h) and time (t). According to equation 27, the height is a quadratic function of time. We therefore cannot use measurements of h to get g. But if we plot h vs. t2 , then we can get a sraight line, the slope of which gives half of the value of g. This is the method we will use to measure g. Method The stand has a meter rule mounted on it, this is used to measure distance of fall between the release mechanism and the landing pad. The meter rule also has two markers to make it easy to measure the position of the landing pad and release mechanism. Before you take the measurements, ensure that the display button on the digital timer is set to milliseconds ms, and the function button is set to timer. Ask the lab technician or facilitator for assistance with this. Clamp the ball-bearing by pushing the release knob and tighten the clamping nut (screw next to the release knob) on the release cable. This will hold the ball-bearing in place. 20 Press the stop button, then reset button and start button on the digital timer (in that order). The green light above the start button will turn on. Raise the landing pad by pulling it up until it cannot move anymore. You are now ready to take a measurement. Note the distance between the release mechanism and the landing pad. Take care of the significant figures. Release the clamping nut by unscrewing it slowly, the ballbearing will fall, starting the counting of the timer. When the ball-bearing hits the landing pad, the counting on the timer will stop. Vary the distance between release mechanism and landing pad. Make a table like the one in table 4 below. h (m) t (s) t2 (s2 ) Table 4: A table of measurements . Perform the following after collecting the data: • Write a MATLAB program to plot height h versus time t. Is the plot linear or quadratic? Remember, your graphs must always have labelled axes with units included. • Use the MATLAB program, fit.m, that is provided to you in Appendix E.1 to fit the data in table 4 (as discussed in the introduction and theory section above) to estimate the value of g. What is the error in your measurement? is the h vs. t2 plot linear? it not, why? Reference • Halliday, D., Resnick, R., Walker, J., Fundamentals of Physics, 9th Edition 21 EXPERIMENT 5 The period and length of a pendulum Aim The aim of this experiment is to determine acceleration due to gravity by investigating the relation between period and length of a pendulum. Introduction and Theory To introduce the concept of ”Acceleration due to gravity”, one should think of two objects of different masses dropping from a certain height from the ground. Both objects will reach the ground at the same time since all objects accelerate at the same rate. The value of this acceleration is denoted by the letter g (Note: We ignore air resistance here). The mass of an object is a measure of its resistance to being put in motion or, if moving, its resistance to being stopped. Mass is measured in SI units called grams. Weight, however, is the pull of gravity on an object. Weight changes depending on the location of the object. It can be found by hanging it from a spring balance. Weight is a force, therefore is measured in SI units called Newtons. Weight is related to mass by: W = mg (28) where g is gravitational acceleration and is constant. However, when using a pendulum to find the value of g, the period of swing of the pendulum depends on the length of the pendulum and the local strength of gravity. Consider an object displaced from an equilibrium position by angle θ and a distance x along the arc (see Fig.7). The equilibrium-restoring force acting on the object is given by: F = −mgsinθ (29) where F is a restoring force, m is the mass of an object, g is gravitaional acceleration and 22 Figure 7: A diagram that shows the forces acting on an object displaced from its equilibrium position by angle θ. θ is the angular displacement. For θ << 1, sinθ ≈ θ, therefore equation (29) becomes: F ≈ −mgθ (30) d2 x dt2 (31) By Newtons second law of motion: F=m Since force defined in equation (30) is tangential, lets make the angle θ = d2 x d2 θ = L dt2 dt2 x , L then (32) where x is the arc length. Using equations (30), (31) and (32) we get: d2 θ g =− θ 2 dt L (33) This is the same as the equation of motion for the simple harmonic motion given by: d2 θ = −ω 2 θ dt2 (34) θ = Asin(ωt + φ) (35) which has the solution 23 where A is an amplitude, φ is the phase and ω is an angular velocity. Exercise: Show that equation (35) is the solution of equation (34). DO THIS EXERCISE BEFORE COMING TO THE LAB. Angular velocity (ω) is related to the period of ascillation as follows: ω= 2π T (36) where T is the period of the oscillation. Now substituting equation (33) and (36) into (34) we get: 2π g − θ=− L T 2 θ (37) Now cancelling the like terms and making T subject gives: s T = 2π L g (38) where T is period, L is the length and g is gravitational acceleration. Squaring both sides of equation 38 and rearranging it gives: T2 = 4π 2 L g (39) This is the equation of a straight line with the term in brackets as a slope. Therefore from the slope of the plot of T2 vs L one can determine the value of g. 24 Method You are provided with 1 retort stand with a clamp, 1 pendulum bob, 1 piece of string (about 1.50 m long), and a stop watch. Assemble apparatus as shown in Fig.8. Figure 8: A diagram that shows apparatus set-up of pendulum experiment (Taken from http://tap.iop.org/vibration/shm/304/page 46587.html). Suspend the pendulum bob from a retort stand and adjust the length (L) of the pendulum, so that it is equal to 1.0m. Displace the bob through a small angle θ and release it to oscillate in the vertical plane. Determine the time for 20 oscillations and determine the time (T) for one oscillation. Repeat this for the lengths of string of 0.90m, 0.80m, 0.70m, 0.60m, 0.50m and 0.40m. Record your results as shown in table 5 including values of T2 . 25 L (m) T (s) T2 (s2 ) 1.0 0.9 0.8 0.7 0.6 0.5 0.4 Table 5: A table for recording the results of the experiment. Plot a graph of T2 (along the vertical axis) vs L (along the horizontal axis). Enter the measurements from table 5 into MATLAB program, fit.m (see Appendix E.1), and fit a straight line through data points and find the slope of the graph. Use equation (39) to calculate the value of g. Answer the following in your report: • Is your data described by equation (39) above? If not, what is the reason for the discrepancy. • What is the value of an acceleration due to gravity and its error, use the standard scientific way of presenting a measurement and its error. • How does the value of g you determined compare with the theoretical value? • Calculate the error in your measured value of g. Reference • http://www.haverford.edu/educ/knight-booklet/accelarator.htm • http://en.wikipedia.org/wiki/Pendulum • http://tap.iop.org/vibration/shm/304/page 46587.html • Haliday, D., Resnick, R., Walker, J., Fundamentals of Physics, 9th Edition. 26 Appendix A A.1 An Introduction to the MATLAB programming language 1 Programming languages A computer program is a set of instructions for a computer to perform a particular task. The task could be as simple as adding two numbers or as complicated as controlling the landing of a jumbo jet aeroplane! In both cases there is a communication between the user and the computer or a machine to be controlled. To effect communication both the user and the computer must understand each other very well. The problem is that a computer language is in binary format (zeros and ones!). Thus there is a need to have a translation between the instructions of a user (who could be speaking any of the known human languages: Setswana, English etc) and the computer language. In other words, there needs to be a mechanism to translate a program (written in human language) into a binary form. This mechanism is in a form of a software called a compiler. 1 Please note: This MATLAB manual is for internal use at the Mahikeng campus of North West University, South Africa only! 27 There are many different compilers available today, each with various capabilities. The compiler that we are concerned with in these notes is called MATLAB which stands for MATrix LABoratory. Indeed one of the strengths of MATLAB is the easy with which it enables the user to manipulate matrices. Some other interesting compilers or programming languages include FORTRAN, C, Pascal, Java, etc. If one wanted to write a computer program for large-scale computing that uses supercomputers of mainframes I would rather use FORTRAN or C. If I wanted to write a program that communicates with machines (such as telescopes etc) I would write such a program in the C language. The power of MATLAB is that it is very easy to learn as it is a high-level language with many built-in functions. In fact, the original MATLAB was written in FORTRAN. The current MATLAB is written in C language. Typically, the following steps are taken in writing and running a successful computer program: • Write a computer program using an editor. An editor is a computer software that allows a user to manipulate text files. Thus one can creates a new text file, adds to an already existing file or removes from it. An example of an editor is Microsoft word, or • Save the program into a text file (called a program file because it contains the program) and run the compiler on the program file. • If there is nothing wrong with the program, the second step above creates a compiled program that can be run by typing its name, or clicking on it. If the user made a mistake in writing the program, the compiler would indicate this by writing an error message on the screen and no compiled program. Then the user has to go step one and correct the mistake and go on to step 2 and 3 above. The above three steps are often repeated (in order 1, 2, 3) many times before the program runs in a correct manner. This is especially the case when very long and complicated programs are being written. 28 A tip: The moral of the story is that when asked to write a computer program, always think of how you would solve the problem without using a computer, say if you had only a calculator! Then break down the problem into little steps. Then plan, STEP-by-STEP, how you would implement the above little steps using the computer program. This will save you long hours in front of a computer! Starting a MATLAB session The MATLAB session is started by clicking the START button on the bottom left of your computer screen. A small window will pop-up with a list of options. One of the options is Programs. If this option is clicked on, another list of more programs will come up. Scroll through all of this list to find MATLAB in the list. Once MATLAB is clicked the window in Fig. A.1 pops up. Figure A.1: MATLAB command window. 29 In the last page we give an outline of how in general one creates a computer program that runs successfully from beginning to the end. Different programming languages deal with steps 2 and 3 differently. Essentially in MATLAB like in all other computer languages you need to type the program as in step 1 in the last page. However, unlike in most FORTRAN compilers (where you always have to create a program file), MATLAB has two modes of operation: • You can type your program at a command line indicated by >> , or • You can create an M-file inside which you will write and save your program: You create the M-file by clicking the File option from the above window in Fig. A.1. • Then select New option to create a new file (see Fig.A.2). As you can see, you can also open an existing M-file (MATLAB program file) and save the program by selecting Save Workspace As Once you have written and saved your M-file, you can run it by selecting Run M-file. We will revisit this option later. Figure A.2: A drop-down window of File option on MATLAB command window. Writing your first MATLAB program Once the window in Fig. A.1 pops up, you are ready to start writing your first program! At a command line (i.e. >>) you can type program statements. 30 Example 1: Type the following program that adds two numbers x=1; y=2; z=x+y The very simple MATLAB program above enters the value for x and y, then assign the sum of x and y to a new variable z. Note that the first two program statements end with the semi-colon (;) each. If you do not put the semi-colon MATLAB prints out the value of the variable after each line. This can be irritating, but perhaps it is good when you want to know the value of each variable after each line. In the third line of the above program we did not include the semi-colon because we want MATLAB to print out the value of z. As a little task, type the above program without the semi-colon in the first and second statements and see what happens. Exercise 1: Write a MATLAB program to do the following: • It enters the value of x and y, and puts the difference between y and x into the variable z. It must also print out the variable z, but not x nor y. • It enters the value of x and y, and puts the product of y and x into the variable z. It must also print out the variable z, x and y. • It enters the value of x and y, and divides y by x and puts the result into the variable z. It must also print out the variable z, x and y. • It enters the values 1.1,1.08,1.11,1.05,1.086,1.12 and works out the average of this. • Can you write a program that calculates the variance of these numbers? 31 Arrays in MATLAB Can you imagine doing the last exercise with 1 million numbers? That is, calculating the mean and variance of 1 million numbers!! Well, with the little knowledge we have of MATLAB so far, this would be a painful exercise indeed!! Not only that, we would have a GIANT program to write! In this section I show you how you can accomplish this task with a few lines of MATLAB program and see the beauty of learning to program. We will not start with a million data points, but rather 20 data points. A special variable that allows you to put many values in it (something like a vector or subscripted variable in maths) is called an array. You can have one-dimentional arrays and multi-dimensional ones that are very much analogous to mathematical arrays. For example, x(i) can be a vector: x=[1,2,5,4,3,6,5,7,8] with nine elements: x(1)=1 x(2)=2 x(3)=5 x(4)=4 x(5)=3 x(6)=6 x(7)=5 x(8)=7 x(9)=8 In MATLAB you create the above vector x(i) by typing: x=[1 2 5 4 3 6 5 7 8] Note that there are no commas (,) between the numbers, just a space between numbers. The following arithmetic is allowed: • y=x+x 32 That will give you: y=[2 4 10 8 6 12 10 14 16] • y=x+2 That will give you: y=[3 4 7 6 5 8 7 9 10] • y=x.*x this means, a new vector y equals the product of vector x and vector x. Thus: y=[1 4 25 16 9 36 25 49 64] • y=x.ˆ n gives a vector x raised to the power n. PLEASE note that MATLAB is case-sensitive, this means that the variable X is not the same as variable x !!! Beware!! Also, avoid giving your MATLAB program files (M-file) names with fancy characters or spaces in between! Exercise 2: Write a MATLAB program to: • create and print an array of x with the following elements: x=[2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.6] • print the square of x • print the square root of x • Calculate the average of the values of x and subtract it from each element. 33 A tip: It is important to check that the program gives the correct answer by taking two or three values you calculated with your program and recalculating them using a calculator. One of the advantages of a computer is that it does not mind to calculate things many things repeatedly, whereas if you tried the same with your calculator you will not only suffer from boredom, but your fingers will soon get tired! Loops in MATLAB Loops are a means to perform tasks repeatedly. A loop needs to have a loop variable that keeps track of each repetition. The following is a simple program that gives an integer i and its square i2 . For i=1:N i,i*i end In the above case, the variable i is a loop variable and the repetition (loop) occurs N times, each loop accompanied by an increase of the loop variable by 1. For the above program to run, you need to specify the value of N before the loop starts. If N=5, the following values of i and i2 will be printed: Number of loops Loop variable i i2 First loop 1 1 Second loop 2 4 Third loop 3 9 Forth loop 4 16 Fifth loop 5 25 Now note the following program: 34 x(1)=1.11 x(2)=1.08 x(3)=1.11 x(4)=1.05 x(5)=1.086 x(6)=1.12 N=6 for i=1:N i,x(i) end it stores the six values into the array x and prints out the contents of the array x. Here is the output of the program: 35 No. of loops Loop variable i x(i) 1 1 x(1)=1.11 2 2 x(2)=1.08 3 3 x(3)=1.11 4 4 x(4)=1.05 5 5 x(5)=1.086 6 6 x(6)=1.12 Here is how you can sum the contents of an array x: x(1)=1.11 x(2)=1.08 x(3)=1.11 x(4)=1.05 x(5)=1.086 x(6)=1.12 N=6 sum=0.0 For i=1:N sum=sum+x(i); end sum Please note that the statement: sum=sum+x(i) means that the new value of the variable sum becomes the old value of sum plus the value of x(i). To show what happens at each stage of the loop, I present a table below: Exercise 3: Now that you know how to use the arrays and loops, I want you to write the following programs: • Use the values of x used in exercise 1, to calculate the standard deviation by means of arrays, using the following equation for the standard deviation (σ): 36 No. of loop Loop variable i x(i) sum 1 1 x(1)=1.11 1.11 2 2 x(2)=1.08 1.11+1.08=2.19 3 3 X(3)=1.11 2.19+1.11=3.3 4 4 X(4)=1.05 3.3+1.05=4.35 5 5 x(5)=1.086 4.35+1.086=5.436 6 6 x(6)=1.12 σ2 = X 5.436+1.12=6.556 (xi − x̄)2 (n − 1) (A.1) where n is the number of data points and x̄ is the mean of the values. Compare your answer with what you get from your calculator. • If you have a set of measurements in x and y, and wish to fit a straight line of the form y=mx+c to the data, the best method of fitting a straight line to a set of data points is the least squares method. The least squares method will give you values of the slope m and the intercept c that give you the straight line that best fit the data. The expressions of m and c that give the best fit are shown below. Also included are expressions for the uncertainties in the slope (∆m) and the uncertainty in the intercept (∆c). m= c= n xi yi − xi yi P 2 P n xi − ( xi )2 P P P P 2P P P xi yi − xi yi xi P 2 P 2 xi − ( n xi ) (A.2) (A.3) and ∆m = v u P 2 u di n t P P n x2 − ( x )2 n − 2 i i 37 (A.4) ∆c = v u u t n(n P 2P 2 di xi P P 2 xi − ( n xi )2 ) n − 2 (A.5) where di = yi − (mxi + c) • Your task is to write a MATLAB program to determine the slope and intercept for the following data: x y 1.0 1.93 2.0 4.01 3.0 5.99 4.0 8.15 5.0 10.0 6.0 11.94 7.0 14.23 • Estimate the error in the slope and the intercept. Making a Plot in MATLAB Making plots is crucial for what we will be doing in the laboratory this year. You will be required to make the plots of the fits to data points and include them in the Microsoft word document report you will submit after every practical. The command for making a plot is plot(x,y) For the above command to be executed successfully, you need to have created arrays x and y. 38 You can also plot data and a line on the same graph with the following commands x(1)=0.0 x(2)=1.0 x(3)=2.0 x(4)=3.0 x(5)=4.0 x(6)=5.0 m=1.5 c=-0.5 y=m*x+c z=x plot(x,y,‘r-‘) hold on plot(x,z,o) hold off The above program will plot the graph on the graph window. If you wanted to include this graph on your Microsoft window. You click File on the top left of the graph window, then select save as. You can then save the graph as a JPEG file that you can include in your document. If you want to plot more than one graphs in the same plot, you type: • plot(x,y,‘o‘,x,y,‘-‘) this will plot data points with o and a solid line on the same plot. 39 To label your axes, you type: • xlabel(x-axis) • ylabel(y-axis) Remember to type the above after you have made your plot with statement: plot(x,y) Upon Termination of a MATLAB session in Command line mode To quit MATLAB, you close all of the MATLAB windows by clicking on the x on the top left corner of each window . When you quit the Command-line session, all the variables that have been using and have assigned values will be lost!! This means that when you start a new session, you will have to assign all the values to your variables! To avoid this, MATLAB has a command SAVE which allows you to save your session in a file called MATLAB.mat. So, typing SAVE, saves all variables you used in your session. However, typing: SAVE X saves only variable X. typing : SAVE X Y Z Saves only variables X, Y and Z. REFERENCES This manual was prepared from a MATLAB manual: MATLAB: High Performance Numeric Computation and Visualization software Users Guide by The MATHS WORKS Inc. August 1992 40 Appendix B B.1 Uncertainties and significant figures NOTE: Parts of this document were adopted from the Physics I PRACTICAL Manual of Potchefstroom campus. Estimating dimensions and accuracy of measurements • When taking measurements always think about the numbers you are getting. Are they close to the numbers you expect? This can be answered by doing calculations from the theory. Also look at the trends in the data and see if it follows the expected trend from theory. For example, if theory predicts an exponential growth in the data, and you notice only linear growth, then there is a problem. Accuracy and Precision • Accuracy: The ability of a measurement to match the actual value of the quantity being measured. • Precision: The ability of a measurement to be consistently reproduced and the number of significant digits to which a value has been reliably measured. • Accuracy of measurement is determined from comparing it to an independent measurement or calculation. 41 • Precision is determined by the measuring instrument used to measure it (consistency to reproduce the measurement) and high number of significant figures. • A measurement is valid (believable) if it is both accurate and precise. Figure B.1: A plot showing a difference between accuracy and precision of measured values relative to the reference or theoretical value. The aim of taking more than one measurement is to make the width of the bell-shaped curve small and close to reference value. Significant figures • Significant figures give the precision with which a number is specified. Thus a number 1.234 has the same precision as 1234. because they have the same number of significant figures (i.e. 4). Example 1: if the length of a wooden board is measured to be 1234 mm, if we change the units to m (metres), then its length is 1.234 m. Hence, the units of measurement does not change the length of the measurement, and precision stays the same. Example 2: If we measure the length of another board to be 751.0 cm. If we convert it to metres, we need to write it as 7.510 m. If we write 7.51 m, we have 42 changed the number of significant figures, and now 7.51 cm is less precise than 7.510 m (it has 4 significant figures, the former has three). Rules for determining Significant figures • Leading zeros in a number do NOT contribute to significant figures as they indicate the scale of the number: For eg. 0.00023 , the three zeros infront of 23 are not significant figures. The only significant figures are 2 and 3. Hence 0.00023 has two significant figures. The first three zeros are leading zeros. • All non-zero digits (1 9) are considered significant • Zeros appearing anywhere between two non-zero numbers are significant, eg. 101.123 has six significant figures: 1, 0, 1, 1, 2, 3 • Trailing zeros in a number containing a decimal point are significant, eg. 1234.300 has seven significant numbers, whereas 1234.3 has five. eg. 0.0000234000 has six significant numbers:(i.e. 2, 3, 4, 0, 0, 0). Scientific Notation Example: 1234 = 1.234×103 1.234 = 1.234×100 0.001234 = 1.23×10−3 All above have four significant figures. Hence are equally precise. Numbers without decimal commas Example: 1 000 000 if we apply the rules for numbers with decimals, the above number should have seven significant figures. But, if we write the above as 1.0×106 then it has only two significant 43 figures! Or if we write it as 1.0000000×106 it has seven significant figures! Bottom line: It will depend on the precision of your measuring instrument. If you do not have any other information, then all the zeros as significant. Exercise 1 • Determine the number of significant numbers for each of the following numbers, and re-write them in scientific notation: 4.863 4.860 468.0 0.000468 0.004680 • Visit the following website: www.physicslessons.com/exp43b.htm and click on Experiment 43 significant figures. Select 10 numbers and determine their significant figures. Handling significant figures during calculations If you are multiplying two numbers with differing significant figures, the product contains fewer or the same number of significant figures as the original number with the least number of significant figures. Example: A = 1357, B = 0.83; A has four significant figures, B has two significant figures. Hence A×B should have two significant figures. A×B = 1357 x 0.83 = 1126.31 B4 = (0.83)4 = 0.47458 = 0.47 A B = 1357 0.83 = 1634.94 = 1.6×103 The above rules also applies to division. 44 Adding and Subtracting When adding/subtracting numbers, the result should have as many significant numbers as the number with the smallest significant figures. Example: • 160.45 + 6.732 = 167.18 • 45.621 + 4.3 - 6.41 = 43.5 However look at this: • 135 + 874 = 1009 = 1.009×103 (it has 4 significant figures) OR • A = 1.002, but A 2 = 0.501 (it has one less significant figure). Calculating Averages The precision of a measurement can be improved by repeating the measurement a number of times. The average contains one significant figure more than the original numbers. Example: Consider the following measurements of length of something: 10.5; 10.4; 10.5; 10.7; 10.3; 10.6; 10.4; 10.5; 10.3 The average is 10.46666666 cm, when applying the above rule the the average is written as 10.47 cm. Example: If the following three lengths were measured: 3.5; 3.5; 3.5 (all in cm), then the average would be 3.50 cm. 45 Multiplying measurements by a constant Multiplying a measurement by a constant, the final answer is unaffected by the significant figures of the constant, but will depend on the significant figure of the measurement itself. Example: If A = 1357, then πA = 3.14159...× 1357 = 4263.14 = 4.26314×103 = 4.263×103 . The final answer has four significant figures as the original value of A. Example: If B = 0.83, then π 2 B = (3.14159...)2 ×0.83 = 8.19177 = 8.2. Final answer has two significant figures like original B. Moral of the Story When analyzing experimental data and writing a report, ensure your answers and measurements have the correct number of significant figures. A measurement is valid (believable) if it is both accurate and precise. Measuring methods The precision of a measurement depends on the precision of the measuring instrument with which the measurement is done. 1. Metre rule The smallest scale division on a metre rule is normally one millimetre (mm). Thus, when measuring with the ruler, the number of whole millimetres of the reading can be decided, but fractions of a millimetre have to be guessed at. Thus, you might measure 1.63 cm, 1.6 is certain, but the number 3 is guessed at. 46 Exercise 2 • Given the blocks of a given mass, Calculate the volume and the density of the block with the correct precision. Compare the density to the table below and decide which metal the block is made of: • Do the following calculations with the correct number of significant figures: Calculate the averages of following sets of numbers: a) 1.99; 1.98; 2.00; 2.01; 2.01 b) 1.99; 1.99; 2.02; 2.01; 2.02 c) 0.99; 0.98; 1.00; 1.01; 1.02 The diameter of a cylinder is 1.62cm. Calculate the: a) radius r, in cm b) r2 , in cm2 c) the volume V = πr2 h, with h = 2.5 cm, in cm3 d) the Volume V, in m3 If the diameter of a wire is d = 0.912 mm, calculate the cross-sectional area of the wire, given by A =πr2 , in m2 , where r is the radius. 47 2. Sliding Calipers 48 Reference These notes were prepared from: PHYSICS: Year Level 1 Practicals: Part 1: First Semester by R.A Burger and H.I Nel, January 2010 (Reviewed) and other sources in the internet. 49 Appendix C C.1 Laboratory report guide Below is a guide line as to how to write your laboratory reports: COVER PAGE: (This page must contain your name and student number, names of your lab partners, title of the experiment you are reporting on and the date in which experiment was done. Remember to write your name first followed by surname, in that order.) INTRODUCTION: (What do you expect to learn? What was the purpose of an experiment you performed? and give theoretical background) MATERIALS: (What equipment and materials did you use for experiment you are reporting on? Describe how any equipment was connected.) PROCEDURES: (What steps did you take to accomplish the aim of an experiment?) RESULTS: (Record the data that you acquired at each step of an experimentation: tables, charts, graphs, sketches, etc. Tables and figures must have captions.) 50 DISCUSSION AND CONCLUSIONS: (Answer all questions under an experiment you performed. Confirm if you achieved the aims of experiment. State the results and their errors obtained. Do your results agree with what is in literature, if not then why? What did you learn? What conclusions can you draw from your results?.) REFERENCE: (Acknowledge any additional material you read to help you compile the report, e.g. a book or webpage) 51 Appendix D D.1 Propagation of Errors For every measurement taken, it is very important to quote its error or uncertainty. It can happen that you need to calculate a quantity that depends on two measurements A and B. Measurement A has an error ∆A and B has error ∆B. How will the uncertainty in C, i.e. ∆C, depends on uncertainties ∆A and ∆B. It depends on the relationship between C, A and B. In the following equations we summarize how the uncertainties in A and B propagate to C: If C=A±B (D.1) q (D.2) then ∆C = (∆A)2 ± (∆B)2 If C=A×B then ∆C = C s ∆A A 2 (D.3) ∆B + B 2 (D.4) If C= 52 A B (D.5) then ∆C = C s ∆A A 2 ∆B + B 2 (D.6) If C = aA (D.7) where a is a number with no error, then ∆C = a∆A (D.8) Example A student wishes to measure the area of a rectangle. She finds one side to be 1.5±0.02 cm and the other side to be 1.0±0.01 cm. What is the area and its incertainty? Answer Area of a rectangle is given by: A=l×b (D.9) and is given that l = 1.5±0.02 cm and b = 1.0±0.01 cm, therefore A = 1.5cm × 1.0cm = 1.5cm2 (D.10) And an uncertainty in area is given by: ∆A = A s 0.02 1.5 2 0.01 + 1.0 2 = 0.016 = 0.02 (D.11) and thus ∆A = 0.02 × A = 0.024cm 53 (D.12) Appendix E E.1 The fit.m program Below is MATLAB program you will be using to fit straight line on the data from the experiments. The program returns the slope, y-intercept, errors and the plot of input measurements. Note that you must edit the program according to the quatities you will have measured during experimentation. x=[300 400 500 600 700 800 900 1000]; y=[16.09 11.59 9.97 8.57 7.96 7.22 6.78 6.59]; n=length(x) sumx=0.0; sumy=0.0; sumxy=0.0; sumxx=0.0; for i=1:n sumx=sumx+x(i); sumy=sumy+y(i); sumxy=sumxy+x(i)*y(i); sumxx=sumxx+x(i)*x(i); end slope=(n*sumxy-sumx*sumy)/(n*sumxx-sumx^2) y_intercept=(sumxx*sumy-sumxy*sumx)/(n*sumxx-sumx^2) z=slope*x+c; 54 plot(x,y,’o’,x,z,’-’) xlabel(’extension (m)’) ylabel(’Force (N)’) % Errors di=y-(slope*x+c); Error_in_slope=sqrt(sum(di.*di)*(n/(n-2))/(n*sumxx-sumx^2)) Error_in_y_intercept=sqrt(sum(di.*di)*sumxx*(n/(n-2))/(n*sumxx-sumx^2)) 55