联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Matlab编程Matlab编程

日期:2018-12-05 11:12

ME 18A

Introduction to Engineering Computation

Rev 11/29/2018 Page 1 of 3

ASSIGNMENT 9

NUMERICAL INTEGRATION

OBJECTIVES

To develop an understanding of numerical integration of data and functions.

To learn how to use MATLAB functions for numerical integration.

To practice programming functions in MATLAB.

GENERAL INSTRUCTIONS

Upon completion of this assignment, you will submit a function m-file, a script, a diary and

several jpegs of plots.

PART 1 - Programming the Trapezoidal Rule

1. Create a MATLAB function (A9P1TRAPlastname.m) that implements the composite

trapezoidal rule. A function to be integrated shall be defined as an anonymous function

and then passed to the user-defined function along with the limits of integration and the

number of segments to be used. The function will return the numerical estimate of the

integral.

2. Integrate the following function over the interval [0 10] analytically (by hand) to

determine the exact solution.

2 + 300 Exact Solution: _____________

3. Develop a script (A91lastname.m) that calls your function A9TRAPlastname.m to

integrate the function given in Step 2 over the interval [0 10] using the following number

of segments

n = [2 3 4 5 10 15 20 30 40 50]

The script shall generate the following plots (3 subplots):

a) the function f(x) vs. x

b) the integral vs number of segments n

c) the percent error vs. number of segments n

Use a logarithmic scale for the percent error axis. Be sure to annotate the plots with axis

labels and titles which include your name and a timestamp. Use the exact solution vs.

the estimate to calculate the percent error. Save the figure (subplots) as

A9P1lastname.jpg.

Note the convergence of the numerical solution to the exact solution with the increasing

number of segments.

ME18A Introduction to Engineering Computation Assignment No. 9

Rev 11/29/2018 Page 2 of 3

PART 2 – Using MATLAB Built-In Quadrature Functions

Record the following exercises in a diary named A9P2lastname.txt. Place your name at the

beginning of the diary and number each problem with a comment line (% Problem X).

1. Use the MATLAB function quad to evaluate the following integrals over the specified

intervals. Check the results with an analytical solution.

a.

( )

+ +

1

0

5 3

600x 400x 20x 2 dx

Exact Solution: _____________

(1 e )dx x

Exact Solution: _____________

c.

( )  +

4

2

3 5

1 x 4x x dx

Exact Solution: _____________

d.

( )+

/ 2

0

8 4sin

x dx

Exact Solution: _____________

2. Table 1 lists velocity data for a vehicle taken at various time intervals. Use the MATLAB

function trapz to determine the distance traveled between t=0 and 10 seconds.

Close the diary.

PART 3 – Numerical Integration Application

To estimate the amount of water that flows in a flood control channel during a one-year period, the height

h of the water and the speed v of the water flow was measured. These measurements were taken at the

beginning of each month, starting on November 1, 2017 with the last measurement taken on November 1,

2018. The measurements were taken at a channel location were the cross section is rectangular with a

width of 20 ft. The height and velocity measurements are listed in Table 2.

Table 1. Vehicle velocity data.

t (s) 0 2 3.25 4.5 6.0 7.0 8.0 8.5 9.3 10

v (m/s) 5 6 5.5 7 8.5 6 6 7 7 5

Table 2. Channel flow measurements.

Day 1 31 60 89 120 152 179 213 240 277 302 334 366

h (ft) 3.0 4.2 4.8 6.5 8.2 8.8 9.8 8.1 6.2 5.4 4.5 3.1 2.9

v (ft/s) 5.4 7.3 8.6 9.7 12.5 13.2 13.5 11.9 9.5 9.1 7.5 5.6 4.3

ME18A Introduction to Engineering Computation Assignment No. 9

Rev 11/29/2018 Page 3 of 3

Develop a MATALB script (A9P3lastname.m) that reads channel flow data from a given file

(A9P3data.txt), uses the data to calculate the flow rate on each day the measurements were taken, and

then integrates the flow rate to obtain an estimate of the total amount of water that flowed in the channel

during the one-year period. An estimate of the instantaneous volumetric flow rate is

= 0.85(ft3

/s)

where v is the velocity (ft/s) at the surface, w is the channel width (ft) and h is the channel height (ft).

Note that this flow rate is calculated in cubic feet per second. The data is given in terms of days, so the

instantaneous flow rate must be multiplied by (60 s/min)(60 min/hr)(24 hr/day) or 86,400 s/day to express

the flow rate in ft3

/day. The total amount of water that flows in the one-year period is estimated by the

integral

= 86,400 ∫2

1

(ft3

)

The data files will list the channel width in the first line and the subsequent lines will have three columns

of data (day, height, speed). Hint: Use fscanf to read the data file. Verify your script is properly reading

the data file by inspecting values in the Workspace window.

The script shall plot the flow rate throughout the year (flow rate vs. day). Annotate the plot with axis

labels and a title which include your name and a timestamp. The annual total estimate shall also

be listed in the plot’s title.

Run the script with the sample data file posted on iLearn (A9P3data.txt). Save the plot as a JPEG

(A9P3lastname.jpg).

Using the assignment submission link on iLearn, submit the following:

Part 1: Function m-file A9P1TRAPlastname.m, the script file

A9P1lastname.m and the plots A9P1lastname.jpg (subplots in one jpeg).

Part 2: The diary A9P2lastname.txt

Part 3: Script file A9P3lastname.m and the plot A9P3lastname.jpg


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp