6 Pages

1. Comp Lab

Course: ENGINEERIN MECH221, Spring 2010
School: UBC
Rating:
 
 
 
 
 

Word Count: 1756

Document Preview

221: Mech Computer Lab 1 Hand in the solutions to the three questions in the lab at the end of the lab. Success in many kinds of engineering requires skill at numerical approximation. The computer labs this term build this skill. This lab in particular will build your understanding of and experience with numerical integration techniques. Some MATLAB commands you already know will be reinforced and some new...

Register Now

Unformatted Document Excerpt

Coursehero >> Canada >> UBC >> ENGINEERIN MECH221

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
221: Mech Computer Lab 1 Hand in the solutions to the three questions in the lab at the end of the lab. Success in many kinds of engineering requires skill at numerical approximation. The computer labs this term build this skill. This lab in particular will build your understanding of and experience with numerical integration techniques. Some MATLAB commands you already know will be reinforced and some new commands introduced. Lab Learning Goals: After completing this lab, you should be able to use MATLAB to: generate vectors and dene functions create plots using either the Command Window or the plot Graphical User Interface write a simple program, save it as an .m le, run it, edit it, and run it again perform numerical integration to a given accurancy Question 1: Dening functions and plotting Let us review how to dene and plot functions in MATLAB. We will also show you how to interface with the plot GUI (Graphical User Interface). You may want to refer to the list of MATLAB commands given in the pre-lab in case you are not familiar with any of the commands used in this lab. Let us start with a few examples. First, we will plot the function f (x) = x2 over the interval [0,1]. Here are some instructions on how to do that: Create a vector x of length 11 containing values between 0 and 1 using the linspace command as follows: >> x = linspace(0,1,11) The vector x corresponds to the end points of 10 equally spaced subintervals of [0,1]. 1 Now we will map these points to the function f (x) = x2 and store the values in the vector y. Enter the following command: >> y = x.^2 Dont forget the dot in the command above, which tells MATLAB to take the square of each entry of x. The command y= x.*x also works, but x*x will give an error message (it tries to use matrix multiplication and the dimensions of the vector x do not allow this). We now have dened our function on the interval. Its time to plot it! We will plot it as a thin red line, with our data points indicated by xs. Type in the following command: >> plot(x,y,r-x) You should now have a window on your screen that contains a plot of y = x2 from x = 0 to x = 1. The next example consists in plotting two dierent functions on the same axis. Specically, we will plot the functions f1 (x) = sin(x) and f2 (x) = sin(x2 ) from x = 0 to x = 2 , using equally spaced points on the x-axis. The distance between successive points on the x-axis is set to 0.01 units. Here are some instructions on how to create these plots: First of all, we clear the workspace and the gure window. To do that, enter the following commands: >> clear all; clf; The clear all command clears all existing variables and other items from the workspace; it also frees up system memory. The clf command clears the current gure window. This practice of clearing the workspace is highly recommended whenever you start a fresh new set of operations in MATLAB. Now create a new vector x containing points between 0 and 2 that increase constantly by 0.01. Since you want to control the step size between vector components, the colon operator : is a better choice to generate the vector x than the linspace command, as shown below: 2 >> x = 0:0.01:2*pi; Now dene the functions by creating two vectors y1 and y2: >> y1 = sin(x); >> y2 = sin(x.^2); You can now create the plots by entering the following: >> >> >> >> plot(x,y1,k-,linewidth,2); hold on; grid on; plot(x,y2,m--,linewidth,2); legend(f1,f2); Take note of what you see in the plot window. Consider what would have happened if we had not included the hold on command. The example above shows how to create plots by specifying command line options. It is also possible to modify the appearance of plots after they have been generated using GUI commands in the plot window. Now that you know how to dene and plot functions, work through the following questions and hand in your answers. Question 1.1: Using any method you prefer, plot the following function on the given interval. Use 21 points (i.e. 20 subintervals) on the x-axis. Plot it as a solid red line of greater than default thickness. Add a grid and give the plot the title Gaussian. Print out this plot and hand it in as part of the lab. f (x) = ex , 2 0x1 Note: the MATLAB command for the exponential function, ex , is exp(x). Question 1.2: Plot on the same axis the following functions on the interval 0 x 1, f1 (x) = sin(2x), f2 (x) = cos(2x) Let the points on the x-axis be spaced 0.025 units apart. Plot f1 (x) using black asterisks with no connecting line, and f2 (x) using black circles with no connecting line. Label your x- and y -axis, x and y respectively. Include an appropriate legend. Print out this plot and hand it in as part of the lab. 3 Question 2: Trapezoidal Method and the Gaussian A very important integral which appears in many dierent disciplines is the Gaussian ex integral: dx 2 (1) In most cases, if you tried to evaluate this quantity analytically you would wind up with a headache. Fortunately we have numerical integration at our disposal. In the following questions you will use MATLAB to estimate a Guassian integral. While the implementation of the numerical method can be straightforward if you use MATLAB built-in functions, it is important that you learn a way to estimate how accurate your numerical calculations are. Question 2.1: Use the trapz command to estimate I = ex dx using 20 0 subintervals. What is the approximate value you obtain? Remember that N subintervals requires N + 1 points. If you are unfamiliar with the trapz command, review the list of MATLAB commands provided in the pre-lab or consult the MATLAB online help by typing help trapz at the command line. Hand in your approximate value of I . Question 2.2: As reviewed in the pre-lab, a good rule of thumb to check if the outcome of your numerical integration is accurate is to double the number of subintervals, N , used to evaluate the integral and observe if the digits of your calculation change. When using a second order or higher method, digits that do not change as N is doubled are usually correct. With this in mind, work through the following problem: Consider the integral I dened in Question 2.1, let TN be the estimate of I computed using the Trapezoidal method. Fill out the following table until you get the value of TN accurate to 3 decimal places. N TN 2 4 8 16 . . . . . . 4 1 2 What value of N is required to reach that accuracy? What is the approximate value for I ? Hand in the answers to these questions along with the table you constructed. Question 2.3: Remember from class that if I is the value of an integral and TN is an approximated value of I computed using the Trapezoidal method with N subintervals, then I TN C/N 2 for N large enough and constant C . This means that I T2N C/4N 2 . We can use this to get that TN T2N 43C2 . Determine an estimate for C and use it N to give an estimate on the accuracy of T20 for the integral dened in Question 2.1. Hand in your estimate of C and the calculations used to get it, and the estimated error in T20 . Question 3: Introduction to .m les and Simpsons Rule To solve large problems in MATLAB it is impractical for you to continuously input commands in the Command Window. A more ecient way is to create and execute an .m le, that is, to write all the sequence of commands to be executed into a text le, save it with the extension .m in your working directory, and then run it in MATLAB. The sequence of commands in an .m le is known as a script. Once written, the script can be run (and modied if needed) repeatedly with little eort. To show you how to create and run .m les, let us start by creating a le with all the commands you used to answer Question 2.1. You can then modify your .m le as needed to work through the nal part of this lab. Here are some instructions to create and execute an .m le: Create a new m.le (File New M-File). If there is no pull-down menu at New, try rst clicking on the Command Window. Type in all the sequence of commands you used to estimate the integral in Question 2.1. Remember to include a semi-colon ; at the end of any line of code whose output you would like to suppress once you run the le. Save the le in the same directory as your Current Directory with the name traprule.m. Be sure to add the .m extension. 5 Go to the MATLAB command window and enter >> traprule MATLAB will now run the script contained in traprule.m. It is also possible to run the script from the editor window (use the button with the green arrow). If no errors appear, your code has been executed. You can easily verify that running traprule.m produces the same result as executing each line of code separately as you probably did when you worked through Question 2.1. Keep in mind that .m les should be saved in your working directory and the lename should not contain spaces. Now that you know how to create, save, and run .m les, you are ready to work through the last part of this lab. Question 3.1: Create an .m le containing all the necessary commands to compute an estimate of the integral of f (x) = x2 sin(x) on the interval 1 x 2, using Simpsons Rule on N = 20 subintervals. Recall that you wrote a similar code as part of your pre-lab assignment. If you are having trouble with errors when you run your .m le, take note of where the error is occurring in your le (MATLAB will tell you) and attempt to debug the problem. When your code runs without errors, check that it is computing the correct quantities by comparing to the exact value of the integral or approximate values computed with trapz. What value did your Simpsons Rule code give you for the approximate value of the integral? Write down the answer and submit it along with a print-out of your Simpsons Rule code. 6
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UBC - ENGINEERIN - MECH221
Mech 221: Computer Pre-Lab AssignmentsTo help you succeed in this course, there will be pre-lab assignments for every computer lab. The goals of the pre-labs are to reinforce concepts taught in class that will be used in the labs and to introduce any new
UBC - ENGINEERIN - MECH221
Mech 2 Computer Lab GuidelinesThe following guidelines apply to all computer labs in Mech 2. For most of MECH 221, 222, and 223, you will complete one computer lab per week.SoftwareThe computer labs use MATLAB (MECH 221 and MECH 222), Unigraphics NX2 (
UBC - ENGINEERIN - MECH221
MECH 2 Dynamics Formula and Data SheetSome Standard Physical Constants:Acceleration at Sea Level due to Gravity: g = 9.81 m/s 2 . Speed of light: c = 3 10 8 m/s . (Nothing in this course goes that fast, so please check your work if you compute a number
UBC - ENGINEERIN - MECH221
Mech 2 Materials Formula and Data SheetStress, Strain, Poissons ratio, elastic moduli:=F , A u , l=Fs , Ap=F , A =lateral strain tensile strainn ==w , l=V V = E n , = G ,p = KF(Fs) = normal (shear) component of force; A = area; u(w) = no
UBC - ENGINEERIN - MECH221
Mech 221 Math Formulae 2010Trigonometrysin = o/h cos = a/h tan = o/a sin x tan x = cos x 2 2 sin x + cos x = 1 sin(x) = sin x cos(x) = cos x sin(x + y ) = sin x cos y + cos x sin y cos(x + y ) = cos x cos y sin x sin y eix = cos x + i sin xh o aQuadra
UBC - ENGINEERIN - MECH221
Mech 2 Mechanics of Materials Formula and Data SheetSome Engineering Material Properties: PropertyYoungs Modulus, E Shear Modulus, G Poissons Ratio, Thermal Expansion, Density, -6Steel210 GPa (30 psi x 106) 81 GPa (11.6 psi x 106) 0.30 11x10 /C (6x10
UBC - ENGINEERIN - MECH221
Mech 221 Math Problems from Old Tests, Week #1Brian Wetton September 20, 2010Notes: This contains all questions on Mech 221 tests and exams from 200609 on the material on numerical methods from the rst four lectures. Some of this material may appear on
UBC - ENGINEERIN - MECH221
UBC - ENGINEERIN - MECH221
Mech 221 Math Suggested Problems Week #1Brian Wetton September 21, 2009Note: Questions #2 and #3 might be a bit tricky. Feel free to ask me or the TA for help with them. 1. Experimental Measurements determine that a function f (x) satises f (0) = 0, f (
UBC - ENGINEERIN - MECH221
Mech 221 Math Problems from Old Tests, Week #2Brian Wetton September 28, 2010Notes: This contains all questions on Mech 221 tests and exams from 200609 on the material on direction elds and rst order linear dierential equations. Some of this material ma
UBC - ENGINEERIN - MECH221
UBC - ENGINEERIN - MECH221
Mech 2 Math Suggested Problems Week #2Brian Wetton September 28, 20101. Experimental Measurements determine that a function f (x) satises f (0) = 0, f (1/4) = 1, f (1/2) = 3, f (3/4) = 6 and f (1) = 8. (a) Estimate1 0f (x)dx using the Trapezoidal rule
UBC - ENGINEERIN - MECH221
UBC - ENGINEERIN - MECH221
Wt-fhM \A~G ~ C) \t4' ~evJ'. 1 .BV)\~~ . Jhc. C9lTlAmh A.a. tlltfop ;c S :I . N\J ~' ~ 'lP(I)'f,\ ~ i ~s) t\;J~-r ~) ~ cJ\ v-ti So ~ v~(fV\.SroD& .IV\.~ ~'I'V\H I\-T t- A-B ( /n-bs).Jr .D'~cJ. E~ ~ ~ vsf- ~ ~0vw~ I I hM- o-rr:L-r
UBC - ENGINEERIN - MECH221
Let-<; f h V\AQ. :~ vv.c;.(' I tMu' r~'d\.-t :~ ~ H"I.) "- a.p p1>)1.;~ rex) ~ MtA.l~O \Ay~~WSe3~ \ l=cfw_).Nl. O'VfNt- .r'" C~p;t~~LtAJe-r P CCf _'- L".cfVt :~,~cio.PU' ~F0JvL crrrJ.u'~ It:!V \-1~\JrJ\ ~r~ ~ t-f~'~ ~ ~ ~,
UBC - MATH - MATH100
MATH 101 - MIDTERM - PRACTICE QUESTIONS.Problem I. (12 pts) Short answer questions. Here you only need to give the correct answer no detailed explanations/ calculations are needed to support your answer. (a) (2 pts) Evaluate sin3 x cos2 x dx(b) (2 pts
UBC - MATH - MATH100
SOLUTIONS MATH 101 - PRACTICE MIDTERM IProblem I. (12 pts) Short answer questions. Here you only need to give the correct answer no detailed explanations/ calculations are needed to support your answer. (a) (2 pts) sin3 x cos2 x dx = 0SOLUTION: Use sy
UBC - MATH - MATH100
Write your Class ID inside this box.MATHEMATICS 101, Section 202 Midterm #1, February 6, 2008 Calculators are not allowed. Show all your work. Use backs of pages if necessary. Unless otherwise indicated, simplification of answers is not necessary. Check
UBC - MATH - MATH100
Write your Class ID inside this box.MATHEMATICS 101, Section 202 Midterm #1, February 6, 2008 Calculators are not allowed. Show all your work. Use backs of pages if necessary. Unless otherwise indicated, simplification of answers is not necessary. Check
UBC - MATH - MATH100
Write your Class ID inside this box.MATHEMATICS 101, Section 202 Midterm #2, March 18, 2008 Calculators are not allowed. Show all your work. Use backs of pages if necessary. Unless otherwise indicated, simplification of answers is not necessary. Check to
UBC - MATH - MATH100
Write your Class ID inside this box.MATHEMATICS 101, Section 202 Midterm #2, March 18, 2008 Calculators are not allowed. Show all your work. Use backs of pages if necessary. Unless otherwise indicated, simplification of answers is not necessary. Check to
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
UBC - MATH - MATH100
Math 101 - Section 208 - Practice Midterm #2Instructor: Michael Lindstrom March 8, 20101 (15 marks: 3 marks each part) a Findex 9+e2x dx. b Find the average value of y = sin( x) on the interval [0, 2 ]. Hint: start with a substitution. c Plot the pola
UBC - MATH - MATH100
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #1 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Section 5.1 Problems 5, 11, 15, 19, 22 Section 5.2 Problems 5, 10, 19, 21, 28, 29, 37, 43, 47, 56, 61, 70Due on Tuesday January 1
UBC - MATH - MATH100
Solution to HW1Page 1Solution to HW1Page 2Solution to HW1Page 3Solution to HW1Page 4
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #2 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Section 5.3 Problems 3, 9, 12, 15, 25, 28, 29, 39, 52, 56, 59, 63, 65, 74 Section 5.4 Problems 3, 6, 11, 23, 25, 30, 35, 39, 44, 5
UBC - MATH - MATH100
Solution to HW2Page 1Solution to HW2Page 2Solution to HW2Page 3Solution to HW2Page 4Solution to HW2Page 5
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #3 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Section 6.1 Problems 1, 4, 5, 9, 13, 16, 19, 24, 25, 26, 31, 33, 45, 50 Section 6.2 Problems 3, 7, 10, 11, 13, 16, 23, 24, 27, 34,
UBC - MATH - MATH100
Math 152, Spring 2010 Assignment #11Notes: Each question is worth 5 marks. Due in class: Wednesday, April 7 for MWF sections; Tuesday, April 6 for TTh sections. Solutions will be posted Wednesday, April 7 in the afternoon. No late assignments will be acc
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #4 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Section 6.4 Problems 4, 7, 11, 9, 13, 16, 19, 24, 25, 26, 31, 33, 45, 50 Problems Plus, Chapter 6: Problems : 6, 12For practice o
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #7 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Write down the initials of your last name on the top right corner of your papers. Section 7.3 Problems 4, 16, 18, 28, 29, 30, 34, 3
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #8 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Write down the initials of your last name on the top right corner of your papers. Section 7.7 Problems 16, 20, 22, 28, 34, 46 Sect
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #9 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Write down the initials of your last name on the top right corner of your papers. Section 8.1 Problems 16, 18, 32 Section 8.3 Prob
UBC - MATH - MATH100
HOMEWORK ASSIGNMENT #10 MATH101.209 - INTEGRAL CALCULUSAll the assignments are from the textbook, unless otherwise specied. Write down the initials of your last name on the top right corner of your papers. Section 9.1 Problems 2, 3, 12 Section 9.3 Probl
UBC - MATH - MATH100
UBC - MATH - MATH100
Solutions to HW 8Page 1Solutions to HW 8Page 2Solutions to HW 8Page 3Solutions to HW 8Page 4Solutions to HW 8Page 5
UBC - MATH - MATH100
Solution to HW 9Page 1Solution to HW 9Page 2Solution to HW 9Page 3
UBC - MATH - MATH100
HW10-solutionsPage 1HW10-solutionsPage 2HW10-solutionsPage 3HW10-solutionsPage 4HW10-solutionsPage 5HW10-solutionsPage 6
UBC - MATH - MATH100
Name:April 2006 Marks [33] 1. Short-Answer Questions. Put your answer in the box provided but show your work also. Each question is worth 3 marks, but not all questions are of equal difficulty. Full marks will be given for a correct answer placed in the
UBC - MATH - MATH100
Name:April 2007 Marks [33] 1. Short-Answer Questions. Put your answer in the box provided but show your work also. Each question is worth 3 marks, but not all questions are of equal difficulty. Full marks will be given for correct answers placed in the b
UBC - MATH - MATH100
Name:April 2008 Marks [21] 1. Short-Answer Questions. Put your answer in the box provided but show your work also. Each question is worth 3 marks, but not all questions are of equal difficulty. Full marks will be given for correct answers placed in the b
UBC - MATH - MATH100
Marks [3]1. Short-Answer Questions. Put your answers in the boxes provided but show your work also. Each question is worth 3 marks, but not all questions are of equal diculty. At most one mark will be given for an incorrect answer. Unless otherwise state
UBC - MATH - MATH100
Name:April2006Mathematics101Page2of11pagesMarks[33]1.Short-AnswerQuestions.Putyouranswerintheboxprovidedbutshowyourworkalso.Eachquestionisworth3marks,butnotallquestionsareofequaldifficulty.Fullmarkswillbegivenforacorrectanswerplacedinthebox,butatmostone
UBC - MATH - MATH100
Name:April2007Mathematics101Page2of11pagesMarks[33]1.Short-AnswerQuestions.Putyouranswerintheboxprovidedbutshowyourworkalso.Eachquestionisworth3marks,butnotallquestionsareofequaldifficulty.Fullmarkswillbegivenforcorrectanswersplacedinthebox,butatmost1ma
UBC - MATH - MATH100
Be sure that this examination has 11 pages including this coverThe University of British Columbia Sessional Examinations - April 2007 Mathematics 101 Integral Calculus with Applications to Physical Sciences and Engineering Closed book examination Time: 2
UBC - MATH - MATH100
April 2008 Marks [21] 1.Mathematics 101Page 2 of 11 pagesShort-Answer Questions. Put your answer in the box provided but show your work also. Each question is worth 3 marks, but not all questions are of equal diculty. Full marks will be given for corre
UBC - MATH - MATH100
The University of British Columbia Final Examination - April 24, 2009 Mathematics 101 All Sections Closed book examination Last Name First Signature Section : Student Number Instructor : Special Instructions: No books, notes, or calculators are allowed. U
UBC - MATH - MATH100
Be sure that this examination has 12 pages including this coverThe University of British Columbia Sessional Examinations - April 2005 Mathematics 101 Integral Calculus Closed book examination Time: 2.5 hoursPrint NameStudent NumberSignatureInstructor
UBC - MATH - MATH100
Be sure that this examination has 11 pages including this coverThe University of British Columbia Sessional Examinations - April 2006 Mathematics 101 Integral Calculus Closed book examination Time: 2.5 hoursPrint NameStudent NumberSignatureInstructor
UBC - MATH - MATH100
PROBLEM 8-3, page 401 (See Problem 8-3. jpg) A horizontal force of P = 100 N is just sufficient to hold the crate from sliding down the plane, and a horizontal force of P = 350 N is required to just push the crate up the plane. Determine the coefficient o
UBC - MATH - MATH100
PROBLEM 12-92, page 48 (See Problem 12-92. jpg) Water is discharged from the hose with a speed of 40 ft/s. Determine the two possible angles ! the fireman can hold the hose so that the water strikes the building at B. Take s = 20 ft.PROBLEM 12-110, page
UBC - MATH - MATH100
Problem 12-110 (page 54) COMPLETION OF PROBLEM 12-110 The trajectory equation isy( x) = a( x ! x0 )2 + b( x ! x0 ) + y0wherea=!g 2v 2 cos2 " 0 0b = tan!0When !0 = 25! , ( x0 , y0 ) = (0, 4 ) ft and ( x, y) = (80, ! 60) ft , it follows that:9.81(80)
UBC - MATH - MATH100
Problems 12-206 and 12-207 (page 96) COMPLETION OF PROBLEMS 12-206 AND 12-207 The rope equation is:l1 + l2 + l3 + l4 = constant The path equations are:l1 + constant = sA l2 + constant = sB l3 + constant = s B l4 + constant = sC Adding the four path eq