Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
FINAL EXAM – CS 151L Spring 2015 Due: Wednesday, May 6, 2015 at 5:00 PM (all M-files must be emailed to TAs by this time) PLEASE READ BEFORE STARTING THE EXAM!!! This is a final exam which means that there is no working with other students in class or getting help from anyone on how to code. However, you may ask questions on the wording or understanding of the problems to either me or the TAs. Any cheating on any of the problems will result in a failing grade in the course. All programs are due on time and there will be no exam programs accepted after the deadline (no exceptions) – 5:00 PM, 5/6/15. REQUIRED NAMING CONVENTION For this exam, use the naming convention as given: Problem 1 should be called cs151sp15exam31.m, Problem 2 called cs151sp15exam32.m, Problem 3 called cs151sp15exam33.m, Problem 4 called cs151sp15exam34a.m and cs151sp15exam34.m, Problem 5 called cs151sp15exam35.m, Problem 6 called cs151sp15exam36.m and Problem 7 called cs151sp15exam37.m. 1. Given the magnitude M of an earthquake on the Richter scale: M 2 E , where E is log 10 3 E0 the energy released by the earthquake, and E0 10 4.4 Joules (energy of a small reference 3 M earthquake) and also noting that E E0 10 2 , create a MATLAB program that determines how many times more energy is released from an earthquake that registers 6.9 on the Richter scale than an earthquake that registers 6.1. To do this, create a single matrix with the two Richter scale values, determine the energy created by each one and divide the energy of the 6.9 by the energy of the 6.1. Print out the value to only two decimal places. (13 points) 1n x 2n . n 1 2n ! value 2. Create a program that calculates the sum of the infinite series: For this program, ask the user to enter x in radians, then create an outer for loop that calculates the sum when value is 2, 4, 6 and 10. Inside this outer loop, use another for loop to create a row vector matrix of terms that can be added (outside the loop) to determine the summation (similar to an example done in class and the program assignment – the loop values should start at 1 and end on the value of the outer loop). After calculating the terms in the inner loop, find the summation of the matrix (NOTE: you will need to add 1 to the summation to get the correct result – takes into account when n=0) and display the result to 6 decimal places. Also, display the result of the 𝑐𝑜𝑠(𝑥) each time to compare it to your calculated values. You can use the factorial function to calculate the denominator of the summation. NOTE: For this problem, you do not have to use a loop within a loop as long as you calculate 4 different answers; one for each of the values 2, 4, 6 and 10. (14 points) Make sure that your programs are correctly named so the TAs can check your work! NOTE: No working together with others to solve problems and no late submissions accepted. FINAL EXAM – CS 151L Spring 2015 Due: Wednesday, May 6, 2015 at 5:00 PM (all M-files must be emailed to TAs by this time) 3. A two-dimensional state of stress at a point in a loaded material is defined by three components of stresses: xx , yy and xy . The maximum and minimum normal stresses (principal stresses) at the point, max and min , are calculated from the stress components by: xx yy xx yy xy (max is defined by the +, min by the -) max,min 2 2 Write a function (cs151sp15exam33) that determines the principal stresses from the stress components. This function will have three input arguments (the three components of stresses) and two output arguments (the maximum and minimum stresses). (13 points) 2 2 x 2 3x 7 using a function (called cs151sp15exam34a) that accepts x 3x 1 one input argument and has one output argument. The input argument is a matrix of the x-values and the output argument is a matrix of the y-values that are calculated using this equation. Since the denominator contains values that cause the denominator to go to zero, you must check to see if any of the x-values are 3 or -1. If either of these values is in the x-values matrix, then your function should display an error and not do the calculation. 4. Plot the equation y Next, create a program (cs151sp15exam34) that creates an x row vector of values from -10 to 1.1 (incrementing by 0.1) and calculates the corresponding y row vector using the above function. Plot these values. Then, create (using the same increment) an x vector of values from 0.9 to 2.9 and corresponding y values and plot these values. For your third plot, use x values from 3.1 to 10 (same increment again) and calculate the y values and plot one more time. All these vectors should create a single plot (plot them all on the same graph) and should represent the given equation (with vertical asymptotes at -1 and 3). (17 points) 5. Write a program that determines the roots of a quadratic equation ax 2 bx c 0 . Your program should ask the user to enter a single vector of three values (the a, b and c coefficients). The first vector value is a, the second one is b and the third one is c. Next, calculate the discriminant of the quadratic equation: d b 2 4ac . If d>0, then the roots of the quadratic b d b d equation are root1 and root 2 . If d=0, then there is only one root which 2a 2a b bi d is root . If d<0, then there are two imaginary roots: root1 and 2a 2a bi d where the second terms in the numerators are the imaginary part of the part. root1 2a After finding the roots, plot the function using x from -20 to 20 (incrementing by 0.1) and calculating the y values using the equation given above. Use an axis of x from -20 to 20 and y from -200 to 400. Then, plot (on the same graph) a straight, horizontal line from (-20,0) to (20,0). NOTE: when entering the values for the input command, you should be using a vector (e.g. [1 -2 -3]). (16 points) Make sure that your programs are correctly named so the TAs can check your work! NOTE: No working together with others to solve problems and no late submissions accepted. FINAL EXAM – CS 151L Spring 2015 Due: Wednesday, May 6, 2015 at 5:00 PM (all M-files must be emailed to TAs by this time) 6. Electrical power is often modeled as P I 2 R where P is the power in watts, I is the current in amps and R is the resistance in ohms. Consider the following data which will be modeled as first-order and second-order equations with the polyfit and polyval functions (you should have new current values defined from 0 to 600 - incremented by 10 - and should determine the power values using the polyval function). You will need to plot the data (original should only be points and curve fitting should be different colors) with the current on the horizontal axis and the power on the vertical axis. (12 points) Power, watts Current, amps 55,000 100 210,000 200 430,000 300 790,000 400 1,250,000 500 7. Given an electrical circuit which consists of resistor and voltage sources, determine the current flows (i1, i2, i3, i4 and i5). Use the following values for the voltage and resistor sources: V1 = 38 volts, V2 = 20 Volts, V3 = 24 Volts R1 = 15 Ohms, R2 = 18 Ohms, R3 = 10 Ohms, R4 = 9 Ohms, R5 = 5 Ohms, R6 = 14 Ohms, R7 = 8 Ohms, R8 = 13 Ohms, R9 = 5 Ohms and R10 = 2 Ohms And, use the following equations to determine the 5 current values: 𝑅9(𝑖5 − 𝑖4) + 𝑅8(𝑖5 − 𝑖3) + 𝑅3(𝑖5 − 𝑖1) + 𝑅10(𝑖5) = −𝑉3 𝑅1(𝑖1) + 𝑅2(𝑖1 − 𝑖3) + 𝑅3(𝑖1 − 𝑖5) = 𝑉1 𝑅4(𝑖2) + 𝑅6(𝑖2 − 𝑖4) + 𝑅5(𝑖2 − 𝑖3) = −𝑉1 𝑅2(𝑖3 − 𝑖1) + 𝑅5(𝑖3 − 𝑖2) + 𝑅7(𝑖3 − 𝑖4) + 𝑅8(𝑖3 − 𝑖5) = 0 𝑅6(𝑖4 − 𝑖2) + 𝑅7(𝑖4 − 𝑖3) + 𝑅9(𝑖4 − 𝑖5) = 𝑉2 You must solve this problem using at least one method from reduced row echelon form, the backslash operator, or the inverse AND using all of the symbolic functions, sym (to create the original equations), subs (to substitute the given voltage and resistance values) and solve (to determine the currents). Print out the values as doubles and be sure to distinguish the value of each current in your program. (15 pts) Make sure that your programs are correctly named so the TAs can check your work! NOTE: No working together with others to solve problems and no late submissions accepted.