Problem

You want to find the roots of an equation graphically.

Solution

Write the equation in the form y = g(x), compute values for y for a given range of x-values, and plot the results using Excel's charting features. Refer to Chapter 4 for more information on charting in Excel.

Discussion

When faced with finding roots to an equation that you can't solve by hand, the first thing I recommend you do is chart it. This will give you valuable insight into the nature of the equation and where its roots lie. If you can write the equation in the form of y = g(x), where x is the independent variable and y the dependent variable, then you can easily set up a few columns computing y for various values of x.

This may all seem trivial and frankly, in terms of spreadsheet operations, it is very simple to perform. However, when dealing with a particularly ugly equation with potentially multiple roots, you'd better have a good idea of where those roots lie. This is because most iterative methods for solving equations require an initial guess as to where the roots lie. Some methods require two initial guesses, while others require you to bracket the roots. The success of these various methods for finding roots lies in the quality of your initial guess. (See the other recipes in this chapter for specific examples.)

Consider the third-order polynomial equation:

This equation has, of course, three roots. That is, there are three values of x that yield a y-value of zero. This is readily confirmed by plotting the curve for y versus x in Excel. Figure 9-6 shows how this particular equation looks when plotted in Excel.

Figure 9-6. Third-order polynomial plot

As you can see, there are indeed three zero crossings; that is, there are three values of x that yield zero for y. To plot this curve, I set up two columns: one containing given values for x and the other containing calculated values for y. These are shown in columns B and C, respectively, in Figure 9-6. I assumed arbitrary coefficients for this example and placed them in cells C2 through C5. The formula bar shows how I constructed the formula for computing y-values corresponding to each x. (Cell C8 is selected in the screenshot, so you see its formula in the formula bar.) The formula is of the form `=$C$2+$C$3*B8+$C$4*B8^2+$C$5*B8^3`.

At this point, you have a clear picture of how this equation behaves and where its roots lie. You have a few options now to actually find the particular values for x that yield y = 0. You can approximate the xs by interpolating between the tabulated values contained in columns B and C. Essentially you look for the xs corresponding to where the y-values go from negative to positive and positive to negative and then interpolate between those tabulated values. Alternatively, you can use iterative techniques to find the x-values. Such techniques are illustrated in Recipes 9.2 and 9.3. Recipe 9.6 shows how to find the roots of the cubic equation discussed here, using Newton's method and the secant method.

Now, let me ask you what happens when you're dealing with an equation that you can't write in the form y = g(x). Well, that presents a problem when you attempt to plot it using the straightforward approach discussed in this recipe. Fortunately, Excel offers other tools that you can leverage to get around such a difficulty. Check out Recipe 9.2 to see what I mean.

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

Flylib.com © 2008-2017.

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

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