Problem

You're dealing with a parabolic or hyperbolic problem and have developed the finite difference equations for the problem, which includes both discretized spatial and time variables. Now you have to solve these equations.

Solution

Use Excel and Solver to solve the finite difference equations in a manner similar to that discussed in Recipe 12.2.

Discussion

In the previous recipe, I showed you how to leverage Solver to solve the finite difference equations, arriving at a steady state solution to an elliptic-type boundary value problem. You can apply the same techniques to solve time-dependent parabolic or hyperbolic types of problems.

Consider the time-dependent one -dimensional heat equation:

This is a parabolic equation, which can be used to model the time-dependent heat conduction in a metal rod, for example, subject to some prescribed initial temperature distribution and boundary conditions at the ends of the rod.

Let's assume we have a 1m rod that's insulated all around except at the ends. The ends of the rod are maintained at a constant 10°C and the initial temperature distribution along the length of the rod (at time t = 0) is as shown in Figure 12-7, row 13. Further assume that c2 equals 1. Now we can use the finite difference method to solve for the temperature distribution along the length of the rod over time.

Erwin Kreyszig solves a similar problem in Advanced Engineering Mathematics.[*] Kreyszig uses the *Crank-Nicolson* finite difference method, where the following finite difference equation applies at each computational node in the finite difference grid:

[*] Erwin Kreyszig, Advanced Engineering Mathematics, 6th ed. (New York: Wiley, 1988).

In this method, both spatial and time variables are discretized. You can set up a finite difference grid similar to that shown in Figure 12-2, where instead of the vertical axis representing the y-dimension, the vertical axis will now represent time. The horizontal axis still represents the x-dimensionthe distance along the rod's length in this case. The finite difference equation shown here assumes that the time step size, Dt, is related to the x step size, Dx, such that Dt =Dx2.

You can solve this problem in a manner similar to that discussed in Recipe 12.2, where I showed you how to solve a boundary value problem using Solver. Figure 12-7 shows the spreadsheet I set up to solve this initial value problem.

The upper table, `Finite Difference Solution`, initially contains only specified boundary and initial values (nonshaded cells) and initial guesses for the unknown temperature values along the length of the rod (shaded cells). We're going to let Solver alter the values in the shaded cells in the upper table to find a solution.

The shaded cells in the lower table, `Residuals-squared`, contain the finite difference equation shown earlier for each node. Actually, the square of the lefthand side, the residual, is computed; the idea is to minimize these residuals as discussed earlier. For example, the formula in cell H22 is `=(4*H8-I8-G8-I9-G9)^2`. All the other cell formulas are similar. Notice that these formulas refer to values contained in the upper table.

Cell D29 contains the sum of all these residual cells. We're going to have Solver attempt to minimize the value computed in cell D29. The Solver model I used for this example is shown in Figure 12-8.

Figure 12-7. Spreadsheet for solving initial value problem

Figure 12-8. Solver model for initial value problem

I set the target cell to D29 so as to minimize the sum of squared residuals. The cells to change are all the shaded cells in the upper table of Figure 12-7. The corresponding cell range is E5 to K12. Pressing the Solve button sets Solver going on its search for a solution. After a few seconds, Solver presents the results shown in Figure 12-9.

Figure 12-9. Final solution to initial value problem

As you can see, all the residuals are 0 and the upper table now contains the solution to this initial value problem. Figure 12-10 shows a plot of these results.

As I mentioned in the previous recipe, the ability to quickly visualize your results in Excel without having to use a separate visualization tool is another compelling reason to use Excel for this sort of problem when possible. Refer to Chapter 4 to learn more about creating charts in Excel.

Figure 12-10. Plot of initial value problem results

Using Excel

- Introduction
- Navigating the Interface
- Entering Data
- Setting Cell Data Types
- Selecting More Than a Single Cell
- Entering Formulas
- Exploring the R1C1 Cell Reference Style
- Referring to More Than a Single Cell
- Understanding Operator Precedence
- Using Exponents in Formulas
- Exploring Functions
- Formatting Your Spreadsheets
- Defining Custom Format Styles
- Leveraging Copy, Cut, Paste, and Paste Special
- Using Cell Names (Like Programming Variables)
- Validating Data
- Taking Advantage of Macros
- Adding Comments and Equation Notes
- Getting Help

Getting Acquainted with Visual Basic for Applications

- Introduction
- Navigating the VBA Editor
- Writing Functions and Subroutines
- Working with Data Types
- Defining Variables
- Defining Constants
- Using Arrays
- Commenting Code
- Spanning Long Statements over Multiple Lines
- Using Conditional Statements
- Using Loops
- Debugging VBA Code
- Exploring VBAs Built-in Functions
- Exploring Excel Objects
- Creating Your Own Objects in VBA
- VBA Help

Collecting and Cleaning Up Data

- Introduction
- Importing Data from Text Files
- Importing Data from Delimited Text Files
- Importing Data Using Drag-and-Drop
- Importing Data from Access Databases
- Importing Data from Web Pages
- Parsing Data
- Removing Weird Characters from Imported Text
- Converting Units
- Sorting Data
- Filtering Data
- Looking Up Values in Tables
- Retrieving Data from XML Files

Charting

- Introduction
- Creating Simple Charts
- Exploring Chart Styles
- Formatting Charts
- Customizing Chart Axes
- Setting Log or Semilog Scales
- Using Multiple Axes
- Changing the Type of an Existing Chart
- Combining Chart Types
- Building 3D Surface Plots
- Preparing Contour Plots
- Annotating Charts
- Saving Custom Chart Types
- Copying Charts to Word
- Recipe 4-14. Displaying Error Bars

Statistical Analysis

- Introduction
- Computing Summary Statistics
- Plotting Frequency Distributions
- Calculating Confidence Intervals
- Correlating Data
- Ranking and Percentiles
- Performing Statistical Tests
- Conducting ANOVA
- Generating Random Numbers
- Sampling Data

Time Series Analysis

- Introduction
- Plotting Time Series Data
- Adding Trendlines
- Computing Moving Averages
- Smoothing Data Using Weighted Averages
- Centering Data
- Detrending a Time Series
- Estimating Seasonal Indices
- Deseasonalization of a Time Series
- Forecasting
- Applying Discrete Fourier Transforms

Mathematical Functions

- Introduction
- Using Summation Functions
- Delving into Division
- Mastering Multiplication
- Exploring Exponential and Logarithmic Functions
- Using Trigonometry Functions
- Seeing Signs
- Getting to the Root of Things
- Rounding and Truncating Numbers
- Converting Between Number Systems
- Manipulating Matrices
- Building Support for Vectors
- Using Spreadsheet Functions in VBA Code
- Dealing with Complex Numbers

Curve Fitting and Regression

- Introduction
- Performing Linear Curve Fitting Using Excel Charts
- Constructing Your Own Linear Fit Using Spreadsheet Functions
- Using a Single Spreadsheet Function for Linear Curve Fitting
- Performing Multiple Linear Regression
- Generating Nonlinear Curve Fits Using Excel Charts
- Fitting Nonlinear Curves Using Solver
- Assessing Goodness of Fit
- Computing Confidence Intervals

Solving Equations

- Introduction
- Finding Roots Graphically
- Solving Nonlinear Equations Iteratively
- Automating Tedious Problems with VBA
- Solving Linear Systems
- Tackling Nonlinear Systems of Equations
- Using Classical Methods for Solving Equations

Numerical Integration and Differentiation

- Introduction
- Integrating a Definite Integral
- Implementing the Trapezoidal Rule in VBA
- Computing the Center of an Area Using Numerical Integration
- Calculating the Second Moment of an Area
- Dealing with Double Integrals
- Numerical Differentiation

Solving Ordinary Differential Equations

- Introduction
- Solving First-Order Initial Value Problems
- Applying the Runge-Kutta Method to Second-Order Initial Value Problems
- Tackling Coupled Equations
- Shooting Boundary Value Problems

Solving Partial Differential Equations

- Introduction
- Leveraging Excel to Directly Solve Finite Difference Equations
- Recruiting Solver to Iteratively Solve Finite Difference Equations
- Solving Initial Value Problems
- Using Excel to Help Solve Problems Formulated Using the Finite Element Method

Performing Optimization Analyses in Excel

- Introduction
- Using Excel for Traditional Linear Programming
- Exploring Resource Allocation Optimization Problems
- Getting More Realistic Results with Integer Constraints
- Tackling Troublesome Problems
- Optimizing Engineering Design Problems
- Understanding Solver Reports
- Programming a Genetic Algorithm for Optimization

Introduction to Financial Calculations

- Introduction
- Computing Present Value
- Calculating Future Value
- Figuring Out Required Rate of Return
- Doubling Your Money
- Determining Monthly Payments
- Considering Cash Flow Alternatives
- Achieving a Certain Future Value
- Assessing Net Present Worth
- Estimating Rate of Return
- Solving Inverse Problems
- Figuring a Break-Even Point

Index

Excel Scientific and Engineering Cookbook (Cookbooks (OReilly))

ISBN: 0596008791

EAN: 2147483647

EAN: 2147483647

Year: N/A

Pages: 206

Pages: 206

Authors: David M Bourg

Similar book on Amazon

- Frame-Mode MPLS Configuration and Verification
- VPN Categories
- L2TPv3 Overview
- Introduction to QoS-Classification and Marking
- Case Study 2: Implementing Multi-VRF CE, VRF Selection Using Source IP Address, VRF Selection Using Policy-Based Routing, NAT and HSRP Support in MPLS VPN, and Multicast VPN Support over Multi-VRF CE

Flylib.com © 2008-2020.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net