Computational Mathematics/Information Technology. Worksheet 2 Iteration and Excel

Similar documents
Computer Worksheet 4

Computational Mathematics

The Bisection Method versus Newton s Method in Maple (Classic Version for Windows)

Using Excel This is only a brief overview that highlights some of the useful points in a spreadsheet program.

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving

MOVING FROM CELL TO CELL

MEI GeoGebra Tasks for A2 Core

Getting Started With Excel

Lab 5 Excel Spreadsheet Introduction

Technology Is For You!

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving Excel Tutorial VIII

GeoGebra Workbook 5 Additions Spreadsheet, Calculus

KINETICS CALCS AND GRAPHS INSTRUCTIONS

Microsoft Excel Lab: Data Analysis

Math 1525 Excel Lab 1 Introduction to Excel Spring, 2001

2. Key the titles in cells A1 to D1, adjust to size 12, click on the bold button, and format with an underline.

ADD AND NAME WORKSHEETS

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

UW Department of Chemistry Lab Lectures Online

Excel tutorial Introduction

Excel and the solution of linear and non-linear simultaneous equations. Part 1

San Francisco State University

Laboratory 1. Part 1: Introduction to Spreadsheets

Introduction to Microsoft Excel

Quickstart for Web and Tablet App

Pre-Lab Excel Problem

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss

= 3 + (5*4) + (1/2)*(4/2)^2.

1) Merge the cells that contain the title and center the title

Microsoft Excel Using Excel in the Science Classroom

Basic tasks in Excel 2013

Activity: page 1/10 Introduction to Excel. Getting Started

Microsoft Excel 2016 LEVEL 2

MEI Casio Tasks for A2 Core

[CALCULATOR OPERATIONS]

Basics: How to Calculate Standard Deviation in Excel

MEI GeoGebra Tasks for AS Pure

Troubleshooting in Microsoft Excel 2002

EXCEL BASICS: PROJECTS

Quickstart for Desktop Version

Rev. C 11/09/2010 Downers Grove Public Library Page 1 of 41

Business Data Analysis MA0123. Dr Gavin Shaddick Department of Mathematical Sciences 4W 5.7

MEI STRUCTURED MATHEMATICS. MEI conference University of Hertfordshire June C3 COURSEWORK

Excel. Spreadsheet functions

Three-Dimensional (Surface) Plots

Quadratic Functions Dr. Laura J. Pyzdrowski

FSA Algebra 1 EOC Practice Test Guide

Microsoft Excel Basics Ben Johnson

CSE100 Principles of Programming with C++

SPREADSHEET (Excel 2007)

Maximizing the Area of a Garden

Appendix A OPENING AN EXCEL SPREADSHEET: To start working with a blank Excel spreadsheet, you should: 1. Log on to your station s computer.

Chemistry Excel. Microsoft 2007

Teach Yourself Microsoft Office Excel Topic 11: Mail Merge

How to use Excel Spreadsheets for Graphing

Experiment 1 CH Fall 2004 INTRODUCTION TO SPREADSHEETS

Physics 251 Laboratory Introduction to Spreadsheets

Microsoft Excel Microsoft Excel

Rockefeller College MPA Excel Workshop: Clinton Impeachment Data Example

Graphing on Excel. Open Excel (2013). The first screen you will see looks like this (it varies slightly, depending on the version):

Spreadsheets. With Microsoft Excel as an example

Labview. Masood Ejaz

Experiment 3 Microsoft Excel in Scientific Applications I

Introduction to Excel Workshop

Outline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014

Introduction to Spreadsheet

FSA Algebra 1 EOC Practice Test Guide

MICROSOFT EXCEL BIS 202. Lesson 1. Prepared By: Amna Alshurooqi Hajar Alshurooqi

HO-1: BASIC SPREADSHEET SKILLS - CREATING A WORKBOOK

Introduction to Excel Workshop

Lab1: Use of Word and Excel

A B C D E F G H I J K L M 1 Student Test 1 Test 2 Test 3 Test 4 Total AVG. Joe Smith

But a vertex has two coordinates, an x and a y coordinate. So how would you find the corresponding y-value?

Chemistry 30 Tips for Creating Graphs using Microsoft Excel

Excel Basics 1. Running Excel When you first run Microsoft Excel you see the following menus and toolbars across the top of your new worksheet

download instant at

Excel. Database functions

Rev. B 12/16/2015 Downers Grove Public Library Page 1 of 40

W7 DATA ANALYSIS 2. Your graph should look something like that in Figure W7-2. It shows the expected bell shape of the Gaussian distribution.

Creating a data file and entering data

6. Essential Spreadsheet Operations

Excel 2007 Fundamentals

Today s class. Roots of equation Finish up incremental search Open methods. Numerical Methods, Fall 2011 Lecture 5. Prof. Jinbo Bi CSE, UConn

Excel Basic: Create Formulas

Tips for working efficiently with Excel's fill handle

Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data

Using Microsoft Excel

Excel Tables and Pivot Tables

Introduction to MS Excel Management Information Systems

Introduction to Spreadsheets Part 1. The Quick and Easy guide to using Openoffice Calc

INFORMATION SHEET 24002/1: AN EXCEL PRIMER

Introduction to Microsoft Excel Parts of the Screen

Introduction to the workbook and spreadsheet

Which of the following toolbar buttons would you use to find the sum of a group of selected cells?

The toolbars at the top are the standard toolbar and the formatting toolbar.

How to stay connected. Stay connected with DIIT

Total Number of Students in US (millions)

1. Setup Everyone: Mount the /geobase/geo5215 drive and add a new Lab4 folder in you Labs directory.

Activity 1 Creating a simple gradebook

Learning Microsoft Excel Module 1 Contents. Chapter 1: Introduction to Microsoft Excel

Transcription:

Computational Mathematics/Information Technology Worksheet 2 Iteration and Excel This sheet uses Excel and the method of iteration to solve the problem f(x) = 0. It introduces user functions and self referencing to carry out the iterations. Notation for instructions Task 1 [Enter] press the enter key <C4> means make C4 the active cell We first look at the solution of the simple quadratic f(x) = x 2 5x + 1 = 0 using the simple rearrangement x = g(x) = 1 + x2. 5 Show that this is indeed a rearrangement of f(x) = 0. Task 2 User function To implement an iterative process of the form x n = g(x n 1 ) we first create the function g(x) within Excel. This is done using the Visual Basic Editor as follows: Select Tools from the top menu. Select Macro Select Visual Basic Editor A new display should appear, with a new top menu. Select Insert from the top menu. Select Module. You should now have a blank window with Module 1 highlighted along the top. Now type the following piece of code: function g(x) [Enter] g=(1+x*x)/5 [Enter] end function [Enter] note: this line appears automatically Now return to Excel Sheet 1 using the Excel button on the top menu. In this sheet we implement two method for carrying out the iteration. The first is a direct method where you are able to view all the elements of the iterative sequence {x n }, however you do have to carry out the iteration manually. The second method uses the ability for Excel to self reference cells and hence carry out the iteration automatically. This method has the advantage of being quick, also there is a facility to cause the iteration to stop automatically when a given accuracy has been achieved. Task 3 Iteration Method 1: direct method 1

To create a header line enter the following: <A1> x(n) [Enter] <B1> g(n) [Enter] The header is not essential, but it helps you to remember what each column refers to. To set up the iteration scheme enter the following. <A3> = 0.5 [Enter] (starting guess x 0 ) <B3> = g(a3) [Enter] (0.25 should appear: g(x 0 )) <A4> = B3 [Enter] (0.25 should appear: x 1 = g(x 0 )) <B4> = g(a4) [Enter] (0.2125 should appear: g(x 1 )) The fixed point iteration scheme has now been set up. Executing the iteration to evaluate the roots. We can now perform as many iterations as we like as follows: Highlight squares A4-B4. Point the cursor to the bottom right hand corner of B4 until it changes to a +. Drag the mouse down to A10:B10 and release. You should see the values of x n in column A. Looking at the accuracy. We need to have some idea whether the sequence is converging. If it is converging, when do we decide to stop? To do this we look at the difference between successive values of x. Add a new column to your table as follows. <C1> error [Enter] <C4> =ABS(A4-A3) [Enter] (0.25 should appear) To calculate the difference for all the iterates point the cursor to the bottom right hand corner of C4 until it changes to a +. Drag the mouse down to C10 and release. You should see that the numbers in column C are getting smaller and smaller. This suggests that the sequence x 0, x 1...is converging. The number in cell C10 gives an estimate for the error in the x value given in A10. Now try changing the initial value in <A3>. and see what happens. Can you make the scheme converge to a different root? What happens if you try a starting condition of 2.0? 3.0? 4.0? 5.0? To obtain the second root to the quadratic it is necessary to use a different rearrangement of f(x) = 0. The next tasks asks you to do this, make the necessary changes to the user function g and then obtain the second root. Task 4 Change the function g(x) 1 Convince yourself that a different rearrangement of f(x) = x 2 5x + 1 is x = 10x 1 x + 5. Change your function g(x) to (10x 1)/(x + 5). Find the second root of f(x) = 0 correct to seven decimal places. (that is to say iterate until the error difference in column C is less than 0.5 10 7. 1 instead of deleting the line g = (1 + x 2)/5 turn it into a comment line by inserting a symbol at the start of the line. Then write another line with g=(10*x-1)/(x+5). Doing this will keep a record of all the g s you have used. 2

Task 5 New problem. Consider finding all the roots of the equation f(x) = x 2sin 2 (x) = 0 using the method of rearrangement and iteration. Show that each of the following are rearrangements of f(x) = 0: x = x + 2sin2 (x) 2 = g(x) x = sin 1 x 2 = g(x) Plot y = f(x) using Derive and hence write down the solutions of f(x) = 0 correct to one decimal place. Use these values as your starting values and the rearrangements above to carry out the iterative process in Excel to obtain the two non-zero roots correct to five decimal places. In your Excel Module for g(x) the function sin 1 (x) is entered as worksheetfunction.asin(x) and x is entered as sqr(x). Hint: always type these function names in lower case. If you type them correctly the Excel will capitalise various letters automatically. If it doesn t then you have made a spelling error a good check. Having to find different rearrangements for different roots is very tedious. Newton s method for constructing the iterative process gets round this problem so long as your starting value x 0 is sufficiently close to the root you are trying to find. Apart from having to start near the required root the only other difficulty with Newton s method is that f (x) may become zero when carrying out the iteration or even worse it may equal zero at the root. In the following we will use the self referencing capability of Excel to carry out the iterations. Task 6 Newton s formula Show on paper that Newton s iterative formula for the solution of the equation f(x) = 4cos x x = 0 is given by x n = 4x n 1 sin x n 1 + 4cos x n 1 4sin x n 1 + 1 = g(x n 1 ) Task 7 Enter the user function g(x) into Excel On you Excel spreadsheet change the user function g(x) to Task 8 Iteration Method 2: self reference. g(x) =(4*x*sin(x)+4*cos(x))/(4*sin(x)+1). Excel allows us to opt for self reference. That is to say we can for example enter =1/(1+A1) into cell A1. This is a very direct form of self reference since we are trying to explicitly put an expression containing A1 in to cell A1. In this case Excel will carry out a default iteration for x n = 1/(x n 1 + 1) with x 0 = 0. Since this is somewhat restricting we employ a variation of this method that allows us to select x 0 before the iteration starts. Carry out the following to set up the above problem for iteration using x 0 = 1 Clear the cells from row 3 down. I.e., just leave the headers To set the option for self reference select Tools, Options, Calculation. Tick the iteration box. Set the max iterations equal to 1 and set maximum change =0.001. 3

In cell A3 enter 1, our starting value x 0 and in cell B3 enter =g(a3). In cell C3 enter =abs(a3-b3). At this stage A3 contains x 0 and B3 contains x 1, C3 contains x 0 x 1 and there is no self reference. Finally in cell A3 type =B3. At this point in the process you have an indirect self reference and Excel will start iterating. Since we have set the maximum number of iterations equal to 1 it will only carry out one step. Keep pressing F9 to repeat the iteration until you have obtained the desired accuracy. Note that the convergence is very fast. The iteration can be made more automatic if we increase the number of maximum iterations. The iteration will then continue until either it has carried out the maximum number of iteration or xn x n 1 x n 1 < maximum change. By plotting y = f(x) using Derive, find two other starting values that give two other roots of the equation. Use your spreadsheet to find these roots. Task 9 Almost the final problem Using Derive 2 to help with the derivative and the algebra show that the Newton iterative scheme for is given by: f(x) = (x 2 1) 5xsin 2 x = 0 x n = 10x 2 n 1 sinx n 1 cos x n 1 x 2 n 1 1 10x n 1 sinx n 1 cos x n 1 + 5sin 2 x n 1 2x n 1 Plot f(x) to obtain suitable starting values for x 0 in order to obtain all the roots of f(x) = 0. Change your function g(x) in Excel and hence using the above self referencing method obtain all the solution of f(x) = 0 correct to seven decimal places. Task 10 The final bit In your Excel Module define for g(x) the function log x. In your Excel Sheet 1 enter <D3> = log(5) [Enter] (This should give you log 5) <D4> = g(5) [Enter] (This should give you log 5) 2 if f(x) is on line #10 and f (x) is on line #11 then you simply author x - #10 / #11 to produce the Newton iteration formula. Simplify, Basic will then do the necessary algebra. 4

Assessment Exercises Worksheet 2 Surname:... Forename... Group No 3. For the Actuarial Science students this sheet is to be handed in at the associated lab session. For Maths students it should be handed in at the second of the two associated lab sessions. Late submission is only allowed with the permission of the lab tutor. 1. For Task 1 write out the steps to show that x = g(x) f(x) = 0. 2. For Task 5 draw a sketch for y = f(x) indicating the non-zero roots of f(x) = 0 correct to 1 decimal place. The non-zero roots, x 1 and x 2 of f(x) = 0 correct to five decimal places are: x 1 =... x 2 =... 3. Write out your solution to Task 6 4. From Task 8 the three solutions to f(x) = 4cos x x = 0 correct to five decimal places are: x 1 =... x 2 =... x 3 =... 5. From Task 10 write out the two answers to 4 decimal places: log 5 =... log 5 =... Give a reason why this is sensible. (You won t get any marks for this reason, but if you come up with a really good answer you may get a job in Microsoft s PR department.) 3 Actuarial Science Students only 5