calculus and differential equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfcalculus and...

23
Chapter 9: Numerical Methods for Calculus and Differential Equations Numerical Integration Numerical Differentiation First-Order Differential Equations Higher-Order Differential Equations

Upload: others

Post on 21-Apr-2021

48 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Chapter 9: Numerical Methods for Calculus and Differential Equations

• Numerical Integration • Numerical Differentiation • First-Order Differential Equations • Higher-Order Differential Equations

Page 2: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Integration Integration is a very important mathematical concept that used is by engineers for many situations. For instance, the pressure distribution on a dam can be used to determine the center of pressure on the dam. The integral of the pressure distribution is the area under the curve.

Page 3: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Numerical Integration Numerical integration is used when the function can’t be integrated directly. The area under the curve is estimated by dividing it using rectangular strips. A more accurate estimate is made by using trapezoidal strips.

Page 4: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Numerical Integration The area of a single trapezoid is given by:

Page 5: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Differentiation Differentiation of a function is the act of calculating the derivative of the function at any point. The derivative is the slope of the curve, which is the tangent line shown below as a red line. The reverse of differentiation is integration.

Page 6: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Numerical Differentiation Numerical differentiation is used for finding the slope of functions that are given by discrete data points, such as experimental data. Three methods are used: • Backward Difference • Forward Difference • Central Difference

Page 7: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Backward Difference Estimate the derivative or slope at a point (𝑑𝑦/𝑑𝑥) by looking at the data point to the left of the point of interest.

Page 8: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Forward Difference Estimate the derivative or slope at a point (𝑑𝑦/𝑑𝑥) by looking at the data point to the right of the point of interest.

Page 9: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Central Difference Estimate the derivative or slope at a point (𝑑𝑦/𝑑𝑥) by looking at the data points to the left and to the right of the point of interest.

Page 10: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

First-Order Differential Equations • Initial-Value Problems • Euler Method • Predictor-Corrector Method • Time-Step Independence

Page 11: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Initial-Value Problems Consider a skydiver falling from an airplane. A Free-Body Diagram of the skydiver is as follows: Newton’s First Law is given by:

𝐹 = 𝑚𝑎

𝑚𝑔 − 𝐹𝐷 = 𝑚𝑑𝑣

𝑑𝑡

Substitute an expression for the Aerodynamic Drag Force:

𝑚𝑔 −1

2𝜌𝑣2𝐴𝐶𝐷 = 𝑚

𝑑𝑣

𝑑𝑡

Weight

Aero Drag

Acc

eler

atio

n

Page 12: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Initial-Value Problems

This is a First-Order Ordinary Differential Equation. In particular, it is called an Initial-Value Problem, because it is solved by knowing an Initial Value of the Dependent Variable. For instance, we can assume that the Downward Velocity of the skydiver was initially zero:

𝑣 = 0 at 𝑡 = 0

Weight

Aero Drag

Acc

eler

atio

n

𝑚𝑔 −1

2𝜌𝑣2𝐴𝐶𝐷 = 𝑚

𝑑𝑣

𝑑𝑡

Page 13: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Euler Method

This Initial-Value Problem can be solved for the skydiver’s velocity as a function of time by using the Euler Method, which starts with the definition of the Derivative:

𝑑𝑣

𝑑𝑡= lim

∆𝑡→0

𝑣 𝑡 + ∆𝑡 − 𝑣(𝑡)

∆𝑡

The derivative can be approximated by allowing ∆𝑡 be a small (but finite) value:

𝑑𝑣

𝑑𝑡≈

𝑣 𝑡 + ∆𝑡 − 𝑣(𝑡)

∆𝑡

𝑚𝑔 −1

2𝜌𝑣2𝐴𝐶𝐷 = 𝑚

𝑑𝑣

𝑑𝑡; 𝑣 = 0 at 𝑡 = 0

Page 14: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Euler Method 𝑑𝑣

𝑑𝑡=

1

𝑚𝑚𝑔 −

1

2𝜌𝑣2𝐴𝐶𝐷

𝑣 𝑡 + ∆𝑡 − 𝑣(𝑡)

∆𝑡=

1

𝑚𝑚𝑔 −

1

2𝜌𝑣2𝐴𝐶𝐷

𝑣 𝑡 + ∆𝑡 = 𝑣 𝑡 +∆𝑡

𝑚𝑚𝑔 −

1

2𝜌 𝑣 𝑡 2𝐴𝐶𝐷

Knowing the Initial Condition, the skydiver’s velocity can now be found by Marching Forward in Time.

Page 15: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Euler Method

𝑣 𝑡 + ∆𝑡 = 𝑣 𝑡 +∆𝑡

𝑚𝑚𝑔 −

1

2𝜌 𝑣 𝑡 2𝐴𝐶𝐷

This equation can be cast into a form appropriate for solution using MATLAB. This is called the Difference Equation:

𝑣𝑘+1 = 𝑣𝑘 +∆𝑡

𝑚𝑚𝑔 −

1

2𝜌 𝑣𝑘

2𝐴𝐶𝐷

where 𝑡𝑘+1 = 𝑡𝑘 + ∆𝑡.

Page 16: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Predictor-Corrector Method The Euler Method assumes that the right-hand side of the equation is constant over the time interval ∆𝑡. The Predictor-Corrector Method provides a more accurate estimate of the right-hand side, which improves the accuracy of the solution. This Two-Step Method uses the Euler Method to Estimate the velocity at 𝑡𝑘+1, then Corrects the Estimate using the Trapezoidal Rule.

Page 17: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Predictor-Corrector Method Euler Prediction:

𝑥𝑘+1 = 𝑣𝑘 +∆𝑡

𝑚𝑚𝑔 −

1

2𝜌 𝑣𝑘

2𝐴𝐶𝐷

Trapezoidal Correction:

𝑣𝑘+1 = 𝑣𝑘

+∆𝑡

2 1

𝑚𝑚𝑔 −

1

2𝜌 𝑣𝑘

2𝐴𝐶𝐷

+1

𝑚𝑚𝑔 −

1

2𝜌 𝑥𝑘+1

2𝐴𝐶𝐷

Page 18: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Falling Skydiver: Euler Method CD = 0.8; % Coefficient of Drag of the Skydiver's Body (Dimensionless) area = 0.4; % Projected Area of the Skydiver's Body, m^2 rho = 1.225; % Density of Air, kg/m^3 mass = 82; % Mass of Skydiver, kg gravity = 9.81; % Acceleration due to Gravity, m/s^2 N = 300; delta_t = 0.1; v = zeros(1,N); t = zeros(1,N); x(1) = 0; % Initial Position, m v(1) = 0.0; % Initial Velocity for k = 1:N v(k+1) = v(k) + (delta_t/mass)*(mass*gravity - 0.5*rho*v(k)^2*area*CD); x(k+1) = x(k) + delta_t/2*(v(k) + v(k+1)); t(k+1) = t(k) + delta_t; end

Page 19: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order
Page 20: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Time-Step Independence

The solution of the differential equation for the skydiver is dependent on the chosen time step ∆𝑡. As the time step size decreases, the solution curves begin to overlap. This is called Time-Step Independence. Conversely, if ∆𝑡 becomes too large, the solution can become unstable, as shown for ∆𝑡 = 5.0 seconds.

Page 21: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Higher-Order Differential Equations The methods used to solve first-order differential equations can be used to solve higher-order ordinary differential equations. Consider a Spring-Mass-Damper system:

Page 22: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Spring-Mass-Damper System

The mass is m, the spring constant is k, and the damping coefficient is c. Newton’s Second Law for this system is:

𝑚𝑥 + 𝑐𝑥 + 𝑘𝑥 = 0 where the first derivative of position with respect to time is

𝑥 =𝑑𝑥

𝑑𝑡 and the second derivative is 𝑥 =

𝑑2𝑥

𝑑𝑡2

Solve this equation by turning it into a system of two first-order differential equations. First, solve the equation for the second derivative:

𝑥 = −𝑐

𝑚𝑥 −

𝑘

𝑚𝑥

Page 23: Calculus and Differential Equationscecs.wright.edu/~sthomas/matlabnoteschap09.pdfCalculus and Differential Equations • Numerical Integration • Numerical Differentiation • First-Order

Spring-Mass-Damper System Let 𝑦1 = 𝑥 and 𝑦2 = 𝑥 . Taking the derivative of the first equation gives:

𝑦 1 = 𝑥 = 𝑦2 or 𝑦 1 = 𝑦2 Taking the derivative of the second equation gives:

𝑦 2 = 𝑥 = −𝑐

𝑚𝑥 −

𝑘

𝑚𝑥 or 𝑦 2 = −

𝑐

𝑚𝑦2 −

𝑘

𝑚𝑦1

Now use Euler’s Method by discretizing the system of equations as follows:

𝑦1,𝑘+1 = 𝑦1,𝑘 + ∆𝑡 ∙ 𝑦2,𝑘

𝑦2,𝑘+1 = 𝑦2,𝑘 + ∆𝑡 ∙ −𝑐

𝑚𝑦2 −

𝑘

𝑚𝑦1