Assignment title: Management


Given a length of wire L cm long, where L is an integer, it is possible, in some cases, to bend the wire into a right angle triangle where the lengths of all the sides are also integers. For example a wire of length L = 12 cm can be bent into a right angle triangle, where the sides are (3; 4; 5). Note that the triangles (4; 3; 5) and (3; 4; 5), and indeed any permutation of these three numbers, are considered to be the same triangle. For this example there is only one possible triangle. Some lengths, such as L = 120 cm, can be bent into a right angle triangle in more than one way, where all of the sides have integer length, ie (30; 40; 50); (20; 48; 52), and (24; 45; 51). Other lengths however can not be bent into a triangle, where the lengths of all of the sides are integers, for example L = 9 cm. (a) Write a function, which has as input a length L, and outputs the unique triple (a; b; c), being the only triangle that the wire can be bent into, where the sides a; b and c all have integer lengths; otherwise it outputs (0; 0; 0). (b) Write a small program, using your function above, to print out all the lengths L, in the range 1800 6 L 6 1950, and their corresponding triangles (a; b; c), for which there is only one possible triangle the wire can be bent into with a; b; c integers. The printout should have (a; b; c), where a; b and c have been ordered such that a < b < c. You may NOT use any of the built in Matlab functions for this question except the fprintf() function. 2. Use the Monte Carlo method to nd: (a) the areas of a circle of radius 5, (b) the volume of intersection of, three cylinders, all of radius 3 units and in nite in length, with the axis of the rst cylinder being the x-axis, the axis of the second cylinder being the y-axis and the axis of the third cylinder being the line with points (1; 1; z) where z 2 R. Part (a) is a simple problem, where the answer is easily calculated, and it will allow you to better understand how the method works. I shall explain the method for the area of a circle and let you generalize it to the second problem. Start with a circle. Draw a square of known area around it (approximately double the area of the circle). Now randomly generate points inside the square. Some of these will fall inside or on the circle and some will fall outside the circle. Since the points are randomly generated you would expect the ratio of, the number of points falling inside or on the circle, to the total number of points, to approximately equal the ratio of, the area of the circle, to the area of 1 the square. Since we know the area of the square, the area of the circle is the only unknown. Rearranging this gives the equation below. Note that the approximation should become more accurate as the total number of points increases. Start with a small number of points while you are developing the program. To get a nal answer use hundreds of thousands, or even millions of points. The only practical limit to the number of points you can use is the computation time. You may NOT use any of the built in Matlab functions for this question except the fprintf() and rand functions. Area of circle  Area of square  number of points inside or on the circle total number of points Note you will need to do the following: 1. Put appropriate comments in your code, including a header that states the pur- pose of the program, its version number, and the date of creation of the program. 2. Hand in a published version of your programs. Also e-mail me a zipped copy of your M- les that I can run, to con rm that they work, to [email protected] The zipped le should include your student number as part of the le name. 3. Do some sorts of checks on your programmes and present your checks and their results in your submission. For example in question 1, you can use the results for the lengths L = 9; 12 and L = 120, for which you know the answers, as a check. For question 2(a) you can check your answer against the exact answer, which you can calculate. In 2(b) there is no exact answer you can check it against, but you can develop your 3D code for a problem you can check, like a sphere at the origin, then modify it for the region given in the question. 4. Programs that simply do not work will be marked down heavily. 2