lab 5 excel spreadsheet introductiongatzke/211/excel1.pdf• excel uses relative referencing for...

22
Lab 5 Excel Spreadsheet Introduction

Upload: others

Post on 26-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Lab 5Excel

Spreadsheet Introduction

Page 2: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 1 – Start Excel

• Under Start, select “All Programs” the “Microsoft Office” then Excel.

• Select the “File” tab and save your file as lab5 on your network drive.

Page 3: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 2 – Spreadsheet Layout

• Excel (and most other spreadsheet programs) organize data and information into rows and columns.

• Click on cell B1 and type in the text

Newton’s Method• Then hit return to put 

the text into that cell.• We will be solving 

Newton’s method starting from x=4 for f(x)=x^2+x‐1

Page 4: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 3 – Column Labels

• Often, when using Excel, data and information is organized in columns.

• Put the following text into the second row, columns A through E:

ixf(x)f’(x)

Page 5: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 4 – Text Formatting

• You can select multiple cells in Excel.

• Click and drag to select the four columns in the second row.  They should be highlighted.

• Click on the “center” function from the Home tab.

• Put the number 1 in cell A3 and the number 2 in cell B3

• Put the following text in cell D1:

f(x)=x^2+x‐1

Page 6: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 5 – Define a Function

• We want f(x) to depend on x. • You can define the function in the 

f(x) column by selecting cell C3 for editing

• You have to type the following:=B3^2+B3‐1• Note that you must start with the 

equals sign to define a function.• After you hit the equals sign, you 

can use the arrow keys to select a cell rather than type in the cell reference.    You can also edit the function in the cell or the function area above.

Page 7: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 6 – Define the Derivative Function

• Select the cell D3 and define the derivative function of x^2+x‐1 in terms of cell B3 as before.

• Change the value of x1 in cell B3 to a value of 4. Your f(4) should be 19 and your f’(4) should be 9.

Page 8: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 7 – Format Columns

• You can select multiple columns at once by clicking on a column label and dragging over to another column label.  The selected columns are highlighted.

• Select column A through D and center the text in all of the cells in those columns.

Page 9: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 8 – Relative Referencing

• Excel uses relative referencing for calculating values.

• In cell A4, put the formula=A3+1• When you copy this cell below, 

the new cells will depend on the value of the cell immediately above. 

• Click on cell A4 then drag the little black dot in the lower right corner down to copy the formula in A4 down the column.

Page 10: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 9 – Check the Formula

• Click on cell A6 and hit the function key F2.  This opens the editor for the formula in that cell.

• Note that the formula in A6 depends on the value in the cell above (A5)

Page 11: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 10 – Newton’s Method

• Click on cell B4 to edit the value that will calculate x2

• Put the following formula in the cell B4:

=B3‐C3/D3• This means that cell depends 

on the value in the column one level above.

• Hit return to stop editing.• Copy cell B4 down the 

column.  You should get an error.  Columns C and D are not defined yet!

Page 12: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 11 – Fix the Functions 

• Select cells C3 and D3 by clicking C3 and dragging to D3.

• Copy these values down to make two new columns.  

• One way to copy, after the cells C3 and D3 are selected, hit Ctrl‐C to copy the formulas to the buffer.  Then, select the cells C4 down to C10 and hit Ctrl‐V to paste.

• Note that f(x) should go rapidly to a value of zero.

Page 13: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 12 – Change the Starting Point 

• You can change the starting point easily to get the other root.

• Change the value for x1 in cell B3 to a value of ‐2

• The other zero is readily found.

• Now change tabs to get a black worksheet.  At the bottom left, click on Sheet2.

Page 14: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 13 – Trapezoidal Integration

• In your second sheet (which should be blank) put text values in the cells as shown to the right.

• Cells A2 through A5: A    b    N    h

• Cells B2 through 4:0    2     10

• Text in D2:  f(x)=x^2+x‐1• Text in D3:  x• Text in E3:  f(x)• Center columns A through E

Page 15: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 14 – Functions

• Make the first value for x depend on the value in B2.

• Enter into D4 the formula to refer to the value a, the start of your derivative:

=B2• Enter into E4 the formula for the 

function f(x) in terms of the x value in the side column.

=D4^2+D4‐1• Enter into B5 the formula for the 

value of h in terms of a, b, N=(B3‐B2)/B4

Page 16: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 15 – Fixed Reference

• The values for xi depend on the previous value of x and h, which remains constant.

• The $ operator fixes a row, column, or both in a formula.

• When a value is fixed in a formula, when copied that value does not change.

• We want the relative reference to be the cell above, but h to be fixed.

• Put into cell D5 the formula=D4+$B$5

Page 17: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 16 – IF Statement

• Copy columns D and E down to row 26.  Note that x goes beyond the integration limit b!

• You can use the IF statement to switch the value of the cell depending on x.  If the condition is true, 1 is in the cell.  If the condition is false, 0 is in the cell.

• Put the following in cell F5:=IF(D5<=$B$3,1,0)• Copy column F down as well.  Note 

that some values in F are 1 and some are 0!

Page 18: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 17 – Trapezoidal Area

• The area of each individual trapezoid depends on the function value at the left and right values of x, h, and the 1 or 0 value showing if x is between a and b.

• Put into cell G5 the formula• =(E5+E4)*F5*$B$5/2• Note that the cell B5 has dollar 

signs to fix the reference to the location of h.  Everything else is relative, so it can be copied down.

• Copy column G down to row 26.

Page 19: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 18 – Sum Function and Ranges

• The sum function adds up cell values.  It can operate on a row, column, or range.

• To specify a range, you have to specify the corners of the range and include a : between the corners.

• Put into cell G2 the formula:=SUM(G5:G26)• Does this match the expected analytical result? • Change the value of h to 0.1.  Does this significantly affect 

your result?  What about if h is 0.01?  • Put h back at a value of 0.1.  

Page 20: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 19 – Turn In

• Make a single page word document to turn in.

• Copy screen shots of Sheet1 and Sheet2 into your word document using PrtScr or the clipping tool.

• Double click the image and select crop to crop down the images to only include the important parts.

Page 21: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 19 – Bonus: Implement Euler Integration

0

2

4

6

0 5 10

x(t)

x(t)

Insert a scatter plot to plot x(t)

dx/dt = RHSx(t+dt) ‐ x(t) = dt * RHSx(t+dt)= x(t) + dt * RHS

Page 22: Lab 5 Excel Spreadsheet Introductiongatzke/211/excel1.pdf• Excel uses relative referencing for calculating values. • In cell A4, put the formula =A3+1 • When you copy this cell

Step 19 – Bonus: Implement Euler Integration

Put all three sheets on a single page to turn in.