'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 13L Fall 215 Test 1 Rebecca A. Simmons & Michael R. Gustafson II Name (please print) NET ID (please print): In keeping with the Community Standard, I have neither provided nor received any assistance on this test. I understand if it is later determined that I gave or received assistance, I will be brought before the Undergraduate Conduct Board and, if found responsible for academic dishonesty or academic contempt, fail the class. I also understand that I am not allowed to speak to anyone except the instructor about any aspect of this test until the instructor announces it is allowed. I understand if it is later determined that I did speak to another person about the test before the instructor said it was allowed, I will be brought before the Undergraduate Conduct Board and, if found responsible for academic dishonesty or academic contempt, fail the class. Signature: Notes You will be turning in each problem in a separate pile. Most of these problems will require working on additional pieces of paper - Make sure that you do not put work for more than any one problem on any one piece of paper. For this test, you will be turning in four different sets of work. Again, please do not work on multiple problems on the same sheet of paper. Also - please do not put work for any problem on the back of any piece of paper. Be sure your name and NetID show up on every page of the test. If you are including work on extra sheets of paper, put your name and NetID on each and be sure to staple them to the appropriate problem. problems without names will incur at least a 25% penalty for the problem. Work must be done in dark ink and on only one side of the page. This first page should have your name, NetID, and signature on it. It should be stapled on top of and turned in with your submission for Problem I. Every other pile should have your test page on top followed by any previously blank paper used for that problem. You will not need and can not use a calculator on this test. You will be asked to write several lines of code on this test. Make sure what you write is MATLAB code and not mathematics. Be very careful with any symbols you use. You do not need to put the honor code statement in your codes. The honor code statement on this page and your NetID on each problem stands in for that.
Problem I:[2 pts.] Basics I (1) Given the following matrices: 4 +9 +3 2 X= +1 7 Y= 5 +3 +9 +9 +5 6 Write the results of the following MATLAB commands; be sure to have the matrix letter near the result so it is clear where your answer for each part is. (a) º (f) Ñ Ü ³µ (b) ÙÑ µ (g) Ñ Ò µµ (c) Ñ Ò µ (h) À Ñ Ò µµ (d) (i) Á ¼ (e) Ò < µ (j) Â Ý Ð Ò Ø µµ (2) Assume you want to plot a surface on a grid where the first independent variable (x1) has 1 linearly spaced values between -π andπand the second independent variable (x2) has 2 linearly spaced values between 1 and e 2. Write the code which would follow the start below that will generate the matrix of points for those independent variables. Also indicate what the variables ÐÔ and Ø store after the second command has run. ܽ ܾ ÐÔ Ø Þ Ü½ µ
Problem II:[25 pts.] Basics II (1) Determine the final contents of the variables É, Ê, and ÐÓ after running the code below: È ½ ½¼ ¹¾ ÐÓ ¼ Ê ½ ÓÖ É È ÐÓ ÐÓ ½ Ê Ê É ½µ È ¾µ Ò (2) Write an anonymous function called Â Û that takes four arguments (a vector or matrix t, a single value start, a single value finish, and a single value height) and calculates the following expression: t< start height Jaws(t, start, finish, height) = (finish t) start t finish finish start t> finish You may assume the user gives you valid inputs and that finish>start. Then use the function to make a plot of Â Û for 61 linearly spaced times between -6 and 6 with a start of -1, a finish of 2, and a height of 3. Plot the function using a dotted blue line with red diamonds at the data points. You do not need a title or axis labels, nor do you need to save the plot. (3) Write a function called ËØ Ø Ô that will take the name or abbreviation of a US state and returns the name of the state capital. You will only need to write the program for North Carolina and South Dakota; if someone gives an input that the function doesn t know, the function should given an error that says ÍÒ ÒÓÛÒ Here are some example runs: State Abbreviation Capital North Carolina NC Raleigh South Dakota SD Pierre Ü ËØ Ø Ô ³ Æ ³µ Ü Ê Ð Ý ËØ Ø Ô ³ ËÓÙØ ÓØ ³µ Ý È ÖÖ Þ ËØ Ø Ô ³ Ì ÒÒ ³µ ÖÖÓÖ Ù Ò ËØ Ø Ô Ð Ò Æ µ ¹¹ Å ÌÄ ÛÖ Ø Ø ÍÒ ÒÓÛÒ
Problem III:[2 pts.] Series Solutions The Taylor series for the natural log of x+ 1 (that is, ln(x+ 1)), for 1< x 1, is given by: f(x)=ln(x+ 1)= ( 1) n x n+1 n+1 (1) Complete the following code segment (modified from Chapra, Figure 4.2) so that your function satisfies all the requirements given in the comment at the top of the function, including handling the default cases: ÙÒØ ÓÒ Ü Ø Ö ÅÝÁØ Ö ÙÒ Ü Ñ Ü Ø µ ± ÅÝÁØ Ö ÙÒ ÁØ Ö Ø Ú ÐÝ ÓÐÚ ÓÖ Ò Ð Ú ÐÙ Ó ÐÒ Ü ½µ ± Ü Ø Ö ÅÝÁØ Ö ÙÒ Ü Ñ Ü Ø µ ± ÒÔÙØ ± Ü Ò Ð ÒÙÑ Ö ÓÖ Û ØÓ Ò ÐÒ Ü ½µ ± ØÓÔÔ Ò Ö Ø Ö ÓÒ ÙÐØ ¼º¼¼¼½µ ± Ñ Ü Ø Ñ Ü ÑÙÑ Ø Ö Ø ÓÒ ÙÐØ ¼µ ± ÓÙØÔÙØ ± Ü Ø Ñ Ø Ú ÐÙ ± ÔÔÖÓÜ Ñ Ø Ö Ð Ø Ú ÖÖÓÖ ±µ ± Ø Ö ÒÙÑ Ö Ó Ø Ö Ø ÓÒ ± ÓÒ ÁØ ÖÅ Ø º Ñ ÖÓÑ ÙÖ º¾ ÓÒ Ô º Ó ± ÔÔÐ ÆÙÑ Ö Ð Å Ø Ó Û Ø Å ÌÄ ÓÖ Ë ÒØ Ø Ò Ò Ò Ö ± ËØ Ú Ò º ÔÖ Ö Ø ÓÒ n= Your program may assume that the user correctly enters a single value for Ü and that if the user also enters values for and/or Ñ Ü Ø that they are 1x1 as well. Your program should must make sure that the value for x is valid, however if it isn t, your function should give an error, ÁÒÚ Ð Ü Once your function checks the number of inputs, assigning defaults as needed, then checks the value of Ü you can write the code for calculating the solution within the given conditions. Important note: the series can start with a ÓÐ of x (since that is the n=term) and build from there. The first iteration solution is thus x when n=, while the second iteration would be the solution once the n=1 term in the series is added (in this case, x x2 2 ). (2) Write a script that uses your new function to produce a graph of the natural log of x+ 1 as a function of x for 2 values of x spanning the valid range of x values. Be careful: recall that this series is valid for 1< x 1, which is different from x 1. All 2 values must be valid. The stopping criterion should be.5 and the maximum number of iterations should be 15. Be sure to label and title the graph and save it in an encapsulated postscript file called ÅÝ Ö Ô º Ô. Use a solid red line with no special symbols at the point to make the graph.
Problem IV:[35 pts.] Zeros and Maxes and Mins 1 The three questions below are related to the graphs on the following page. Each graph is for a different question. (1) Given f(t) in (1) above: f(t)= (t4 + 2t 3 2t 2 6t+ 1) e (t2 ) (a) Write an anonymous function ÙÒ that takes the input Ø and calculates the value of f(t) for any size matrix Ø. (b) Add code that is guaranteed to find the times of the two roots of the function that are between times -2 and 2. The times should go into variables called ÊÓÓØÌ Ñ ÇÒ and ÊÓÓØÌ Ñ ÌÛÓ (c) Add code that is guaranteed to find the times and function values for the two local minima that are between times -2 and 2. The times should go into variables called Å ÒÌ Ñ ÇÒ and Å ÒÌ Ñ ÌÛÓ, while the values of the function at those times should go into variables called Å ÒÎ ÐÇÒ and Å ÒÎ ÐÌÛÓ. (d) Add code that is guaranteed to find the time and function value for the local maximum. The time should go into a variable called Å ÜÌ Ñ and the value of the function at that time should go into a variable called Å ÜÎ Ð. (2) Given g(x) in (2) above: g(x)= 3x 3 x 3 + x 2 + x+ 2 (a) Write an anonymous function ÙÒ that takes the input Ü and calculates the value of g(x) for any size matrix Ü. (b) Add code to that is guaranteed to calculate x values for values of g(x) from -2.25 to 2.25 with.75 between them, then print those values to the screen exactly as shown below: Ò Ë Ø ¹ º ½¼ ¹¼½µ ¹¾º¾ ¹ º ¾ ¹¼½µ ¹½º ¼ ¹ º½¼ ¹¼½µ ¹¼º ¹½º ¾ ¹½ µ ¼º¼¼ ½º½ ¼¼µ ¼º ¾º¼¼¼ ¼¼µ ½º ¼ º¼ ¾ ¼¼µ ¾º¾ (3) Given h(x, y) whose contour plots are portrayed in (3) above: h(x, y)=sinc(x.4) sinc(y.2) and assuming (correctly) that MATLAB has a built in function called Ò, (a) Write the code to create the contour plot graph above. Note that the contours were made to range from -.2 to 1 with a spacing of.2, the points used to make the contour plot have domains in each direction from -3 to 3, and there are 51 different independent values in each direction. (b) Based on the contour plot, write code to find the exact x and y coordinates of all four local minima. The points should end up in a single 4x2 matrix with the x coordinates in the first column and the corresponding y coordinates in the second column. The points may appear in any order. 1 Oh my!
.2 2 3 2 2 1 f(t), V 4 g(x), m 6 1 8 2 1 3 2 1 1 2 3 t, s 3 3 2 2 4 6 8 1 x, m (1) (2) Contours of h(x,y) 2 1.2.2.8.4.6.2 y 1.4.2.6.2.2 2 3 3 2 1 1 2 3 x (3)