Chapter 7 PDF
Chapter 7 PDF
Engineering Applications
(GENG-8030)
By:
Dr. Mohammad Sedigh Toulabi
Lecture number:
(8)
Winter 2023
Numerical methods for calculus and differential equations:
Integral
Integral of f(x) interpreted as the area A under the curve of f(x) from x a
to x b
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 2
Integral:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 3
Numerical integration functions:
Command Description
integral(fun,a,b) Uses an adaptive Simpson’s rule to compute
the integral of the function whose handle is
fun, with ‘a’ as the lower integration limit and
‘b’ as the upper limit.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 4
Numerical integration functions:
Although the integral function is more accurate than trapz, it is restricted to
computing the integrals of functions and cannot be used when the integrand
is specified by a set of points. For such cases, use the trapz function.
sin x dx
0
First use 10 panels with equal widths of /10. The script file is
The answer is 1.9797, which gives a relative error of 100 ((2 1.9797)/2)
1%.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 5
Numerical integration functions:
Script to integrate 2 from 0 to , create the function:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 6
Polynomial integration:
Which corresponds to .
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 7
Double integrals:
A = integral2(fun, a, b, c, d) computes the integral of from x a to
b, and y c to d.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 8
Triple integrals:
computes the triple integral of
from to to , and to .
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 9
Question:
Q1-A tank having vertical sides and a bottom area of 100 ft2 is used to store
water. The tank is initially empty. To fill the tank, water is pumped into the
top at the rate given in the following table. Determine the water height h(t)
at t = 10 min.
Time (min) 0 1 2 3 4 5 6 7 8 9 10
Flow rate (ft3/min) 0 80 130 150 150 160 165 170 160 140 120
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 10
Question:
Q2-An accelerometer is used in aircraft, rockets, and other vehicles to
estimate the vehicle’s velocity and displacement. The accelerometer
integrates the acceleration signal to produce an estimate of the velocity, and
it integrates the velocity estimate to produce an estimate of displacement.
Suppose the vehicle starts from rest at time t = 0, and its measured
acceleration is given in the following table.
0 1 2 3 4 5 6 7 8 9 10
0 2 4 9 16 17 24 32 41 48 51
The estimated velocity v after 10s is.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 11
Question:
Q3-Use the integral function to compute the integral
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 12
Numerical differentiation:
Illustration of three methods for estimating the derivative .
A backward difference
B forward difference
C central difference
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 13
Numerical differentiation:
MATLAB provides the diff function to use for computing derivative
estimates. Its syntax is d = diff(x), where x is a vector of values, and the
result is a vector d containing the differences between adjacent elements in
x.
For example, if x = [5, 7, 12, -20], then diff(x) returns the vector [2, 5, -32].
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 14
Polynomial differentiation functions:
Command Description
b = polyder(p) Returns a vector b containing the coefficients
of the derivative of the polynomial
represented by the vector p.
[num, den] = polyder(p2,p1) Returns the vectors num and den containing
the coefficients of the numerator and
denominator polynomials of the derivative
p2/p1
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 15
Polynomial differentiation functions:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 16
Solving first order differential equations:
An ordinary differential equation (ODE) is an equation containing
ordinary derivatives of the dependent variable. An equation containing
partial derivatives with respect to two or more independent variables is a
partial differential equation (PDE). Solution methods for PDEs are an
advanced topic, and we will not treat them in this text.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 17
Solving first order differential equations:
ode45 is used as follows to solve
where @ydot is the handle of the function file whose inputs must be and ,
and whose output must be a column vector representing ; that is,
. The number of rows in this column vector must equal the order of
the equation.
• The array tspan contains the starting and ending values of the independent
variable t, and optionally any intermediate values.
• The array y0 contains the initial values of . If the equation is first order,
then y0 is a scalar.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 18
Response of an RC circuit:
The circuit model for zero input voltage v is
Analytical solution :
1.5
0.5
0
0 0.1 0.2 0.3 0.4 0.5
Time(s)
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 19
Nonlinear example:
The equation for the height is
dh 0.0344 h
dt 10h h 2
Draining of a
spherical tank
10
-2
0 500 1000 1500 2000 2500
Time(s)
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 20
Extension to higher order equations:
To use the ODE solvers to solve an equation higher than order 2, you must
first write the equation as a set of first-order equations.
For example, consider the equation
5
y 7 y 4 y sin(t )
x1 x2
1 4 7
x2 sin(t ) x1 x2
5 5 5
This form is sometimes called the Cauchy form or the state-variable form.
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 21
Extension to higher order equations:
x1 x2
1 4 7
x2 sin(t ) x1 x2
5 5 5
Suppose we want to solve the equation for 0
t 6 with the initial conditions x1(0) 3,
x2(0) 9.
10
4 Plot of x2
2
-2
-4
0 1 2 3 4 5 6
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 22
Pendulum example:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 23
Pendulum example:
1.5
0.5
-0.5
-1
-1.5
-2
0 1 2 3 4 5
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 24
A mass and spring:
A mass and spring with viscous surface friction. Its equation of motion is
my cy ky f (t )
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 25
A mass and spring:
The equation of motion can be put into the state
variable form. Assuming and we have
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 26
A mass and spring:
Plot of x1
For and
The equations can be solved and the
solution plotted follows.
Plot of x2
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 27
Question:
Q4-Use MATLAB to evaluate the following double integral:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 28
Question:
Q5- Use MATLAB to evaluate the following triple integral:
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 29
Question:
Q6- Use MATLAB to compute and plot the solution of the following
equation.
at is around:
(correct) 21
20
19
18
17
16
15
0 10 20 30 40 50 60 70
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 30
Question:
Q7- Plot the position and velocity of a mass with a spring and damping,
having the parameter values , , and . The applied force is
, the initial position is , and the initial velocity is
.
The displacement at is
(correct) 6
5.5
4.5
3.5
2.5
1.5
0 1 2 3 4 5 6
Computational methods and modeling for engineering applications (GENG-8030) By: Dr. Mohammad Sedigh Toulabi 31