You are on page 1of 3

MEEN

357

Engineering Analysis for Mechanical Engineers


Assignment 6: Numerical Integration + ODE

Fall 2012

Assigned: Due Date: Due Time: October 16 October 24 12 PM CST (hard copy) 5 PM CST Submission: Electronic/Hardcopy Collaboration Type: Individual Grading: 30 pts

Assignment Purpose: The purpose of this assignment is to help you build your understanding of methods for numerical differentiation and integration. Assignment Instructions: Complete the tasks given below. The standard policy on collaboration is in effect. Submission Instructions: Although some coding is involved, all submissions are to be done in hard-copy format. As always, your submission should include any deliverables for the tasks and your collaboration statement (if applicable). Hard copy has to be submitted in class at 12 PM CST. Submissions note: Please submit your explanations/answers to questions as a hard copy of a typed documentno hand-written responses please. Electronic submission (for programming assignments) should be done within a folder with the following name: A06_MEEN357_501_FamilyName_FirstName.zip. Grading Policy: This assignment is worth 30 points. Task 1: Write a code a06_romberg_int.m (4 pts) Write a program to implement Romberg integration. Note that you need to provide the program with a function name fun, which is actually the name of a matlab file that evaluates f(x) function I = a06_romberg_int(func,a,b,es,maxit) % I = a06_romberg_int(func,a,b,es): % Romberg integration. % input: % func = name of function to be integrated % a, b = integration limits % es = (optional) stop criterion (%); default = 0.00001 % maxit = (optional) max allow iterations; default = 30 % output: % I = integral estimate Specifications: Function should check if b is larger than a Deliverables: Matlab file a06_romberg_int.m Program Listing (Hard Copy)

10/16/12

(assignment continues on next page)

MEEN 357

Engineering Analysis for Mechanical Engineers

Fall 2012

Task 2: Euler Method (5 pts) Write a program to implement Eulers Method. [t,y] = a06_ode_Euler(diffeq,tspan, y0, ssize) % diffeq = (string) name of the m-file that evaluates the right hand side of the ODE written in standard form % tspan = Time span [t0,tf] % y0 = initial condition for the dependent variable % ssize = stepsize for advancing the independent variable % Output: % t = vector of independent variable values: t(j)=(j-1)*h % y = vector of numerical solution values at the t(j) THIS CODE SHOULD BE ABLE TO HANDLE SYSTEMS OF ODEs AS WELL Specifications: Function should check that tspan is a 1-D array Function should check that ssize is a scalar Function should check that y0 is a scalar OR a 1-D array Deliverables: Matlab file a06_ode_Euler.m Program Listing (Hard Copy) Task 3: Runge-Kutta, fourth order (5 pts) Write a program to implement Runge-Kuta 4th Order Method. [t,y] = a06_ode_RK4(diffeq,tspan,y0,ssize) % diffeq = (string) name of the m-file that evaluates the right hand side of the ODE written in standard form % tspan = Time span [t0,tf] % y0 = initial condition for the dependent variable % ssize = stepsize for advancing the independent variable % Output: % t = vector of independent variable values: t(j)=(j-1)*h % y = vector of numerical solution values at the t(j) THIS CODE SHOULD BE ABLE TO HANDLE SYSTEMS OF ODEs AS WELL Specifications: Function should check that tspan is a 1-D array Function should check that ssize is a scalar Function should check that y0 is a scalar OR a 1-D array Deliverables: Matlab file a06_ode_RK4.m Program Listing (Hard Copy)

10/16/12

(assignment continues on next page)

MEEN 357

Engineering Analysis for Mechanical Engineers

Fall 2012

Task 4: Solution to Text Problem (5 pts) Create a script named a06_25_4.m that solves the differential equation in problem 25.4. You should also provide with the function a06_function_25_4.m that implements the differential equation. Your code should call your a06_ode_RK4 code. No MATLAB ODE solver allowed. The script should output a properly formatted figure of the behavior of y(1) and y(2) vs t. Deliverables: Matlab file a06_25_4.m and a06_function_25_4.m Program Listing (Hard Copy) Task 5: Solution to Text Problem (5 pts) Create a script named a06_25_20.m that solves the differential equation in problem 25.20. You should also provide with the function a06_function_25_20.m that implements the differential equation(s). You may use any MATLAB ODE solver you want. The script should display a properly formatted solution (i. e. The time to empty the tank is xx seconds.) The script should also plot the height of water in the tank as a function of time. Use proper labels and legends. Deliverables: Matlab file a06_25_20.m and a06_function_25_20.m Program Listing (Hard Copy) Task 5: Hard Copy Problems (6 points) Problem 25.1 Problem 25.4 Problem 25.7

10/16/12

(assignment continues on next page)