23
Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Robert F. Murphy Copyright Copyright 1996, 1999, 1996, 1999, 2000, 2001. 2000, 2001. All rights reserved. All rights reserved.

Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright 1996, 1999, 2000, 2001. All rights reserved

Embed Size (px)

Citation preview

Page 1: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Computational Biology, Part 13Spreadsheet Basics II

Computational Biology, Part 13Spreadsheet Basics II

Robert F. MurphyRobert F. Murphy

Copyright Copyright 1996, 1999, 2000, 2001. 1996, 1999, 2000, 2001.

All rights reserved.All rights reserved.

Page 2: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

RecalculationRecalculation When a cell value is changed, what determines When a cell value is changed, what determines

whether other cells are recalculated? There are whether other cells are recalculated? There are two options:two options: AutomaticAutomatic

The program recalculates every cell (if necessary) every The program recalculates every cell (if necessary) every time a cell changestime a cell changes

This is the default for most spreadsheet programsThis is the default for most spreadsheet programs

ManualManual The program waits for a user command before The program waits for a user command before

recalculatingrecalculating

Page 3: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Recalculation orderRecalculation order When cells refer to each other, what determines When cells refer to each other, what determines

the order in which the calculations are done?the order in which the calculations are done? Some (older) spreadsheets calculate cell values Some (older) spreadsheets calculate cell values

in a set order.in a set order. ColumnwiseColumnwise

Top to bottom for 1st column then 2nd column...Top to bottom for 1st column then 2nd column... A1 to AA1 to Ann, B1 to B, B1 to Bnn, C1 to C, C1 to Cnn, etc., etc.

RowwiseRowwise Left to right for 1st row then 2nd row...Left to right for 1st row then 2nd row...

Page 4: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Forward ReferencesForward References A formula that refers to a cell “ahead” in the A formula that refers to a cell “ahead” in the

recalculation order of the cell containing the recalculation order of the cell containing the formula is called a formula is called a forward referenceforward reference..

If the recalculation order is If the recalculation order is columnwisecolumnwise, , references to cells to the references to cells to the rightright of the cell of the cell containing the formula are forward references.containing the formula are forward references.

If the recalculation order is If the recalculation order is rowwiserowwise, references to , references to cells cells belowbelow the cell containing the formula are the cell containing the formula are forward references.forward references.

Page 5: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Example of forward referenceExample of forward reference

Given the following formulas, are there any Given the following formulas, are there any forward references if the recalculation order forward references if the recalculation order is is rowwiserowwise??

Page 6: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Example of forward referenceExample of forward reference

Given the following formulas, are there any Given the following formulas, are there any forward references if the recalculation order forward references if the recalculation order is is rowwiserowwise??

Yes, cell B2 has a forward reference to A3.Yes, cell B2 has a forward reference to A3.

Page 7: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Example of forward reference?Example of forward reference?

Given the following formulas, are there any Given the following formulas, are there any forward references if the recalculation order forward references if the recalculation order is is columnwisecolumnwise??

Page 8: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Example of forward reference?Example of forward reference?

Given the following formulas, are there any Given the following formulas, are there any forward references if the recalculation order forward references if the recalculation order is is columnwisecolumnwise??

No, the results areNo, the results are

Page 9: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Dynamic recalculationDynamic recalculation

Modern spreadsheets do not recalculate in Modern spreadsheets do not recalculate in any set order. They any set order. They dynamicallydynamically determine determine which cells need to be updated.which cells need to be updated.

Page 10: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Circular referencesCircular references

A formula that refers to a cell containing a A formula that refers to a cell containing a reference to the original cell is called a reference to the original cell is called a circular referencecircular reference..

Circular references can only be resolved by Circular references can only be resolved by iterationiteration, following the recalculation order., following the recalculation order.

Circular references may either Circular references may either convergeconverge or or divergediverge, depending on whether they , depending on whether they approach a limiting value or not.approach a limiting value or not.

Page 11: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Example of circular referencesExample of circular references

The following cells contain circular The following cells contain circular references. Are they convergent or references. Are they convergent or divergent?divergent?

Page 12: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Enabling iterationsEnabling iterations If we enter these formulas into cells A1 and B1, If we enter these formulas into cells A1 and B1,

the program will give an error messagethe program will give an error message

In order to use a spreadsheet with circular In order to use a spreadsheet with circular references, we need to set the program to use references, we need to set the program to use iterations to attempt to resolve the references.iterations to attempt to resolve the references.

Page 13: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Enabling iterationsEnabling iterations

For Excel, select For Excel, select Options... Options... from from ToolsTools and and select the select the CalculationCalculation tab. The default tab. The default settings should be shown. settings should be shown.

Page 14: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Enabling iterationsEnabling iterations Check the Check the IterationIteration box and leave the default of box and leave the default of

100 for 100 for Maximum IterationsMaximum Iterations. Note that . Note that calculation options are saved along with the calculation options are saved along with the spreadsheet and set when loading a spreadsheet spreadsheet and set when loading a spreadsheet IF IT IS THE FIRST ONE LOADEDIF IT IS THE FIRST ONE LOADED..

The program should begin calculating values, The program should begin calculating values, ending with a number very close to 1 in cell A1 ending with a number very close to 1 in cell A1 and a number very close to 2 in cell B1.and a number very close to 2 in cell B1.

Page 15: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Convergent circular referencesConvergent circular references

Here is a graph of the values in the cells Here is a graph of the values in the cells versus iteration number.versus iteration number.

Convergent Circular References

0

1

2

1 4 710 13 16 19 22 25 28

Iteration

Cell Value

A1=B1/2

B1=A1+1

Page 16: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Another exampleAnother example

Are the following circular references Are the following circular references convergent or divergent?convergent or divergent?

Page 17: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Divergent circular referencesDivergent circular references

Here is a graph of the values in the cells Here is a graph of the values in the cells versus iteration number.versus iteration number.

Divergent Circular References

0

10000

20000

30000

1 5 913 17 21 25 29

Iteration

Cell Value

A1=B1*2

B1=A1+1

Page 18: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Self references and initial valuesSelf references and initial values Cells can make circular references to themselves Cells can make circular references to themselves

(called (called self referencesself references).). Excel assumes a value of Excel assumes a value of zerozero for a cell before for a cell before

the first iteration of a self reference (or a circular the first iteration of a self reference (or a circular reference to a cell that has not yet been reference to a cell that has not yet been evaluated).evaluated).

Thus, entering Thus, entering =A1+1 =A1+1 into cell A1 will result in into cell A1 will result in the value 100 (assuming maximum iterations is the value 100 (assuming maximum iterations is set to 100).set to 100).

Page 19: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Using manual recalculation for circular referencesUsing manual recalculation for circular references In a complicated model involving circular In a complicated model involving circular

references, it is often useful to turn off references, it is often useful to turn off automatic recalculation so that you can automatic recalculation so that you can control when recalculation is done (e.g., control when recalculation is done (e.g., after all formulas have been entered). after all formulas have been entered). Recalculation can be initiated using Recalculation can be initiated using ==..

Page 20: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Summary: RecalculationSummary: Recalculation

Recalculation TimingRecalculation Timing AutomaticAutomatic or or ManualManual

Recalculation OrderRecalculation Order ColumnwiseColumnwise, , RowwiseRowwise or or DynamicDynamic

Circular ReferencesCircular References Resolved by Resolved by iterationiteration ConvergentConvergent or or divergentdivergent

Page 21: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Goal SeekGoal Seek

Varies one cell in order to have another cell Varies one cell in order to have another cell reach a particular valuereach a particular value

Uses a non-linear fitting method with Uses a non-linear fitting method with empirical derivativesempirical derivatives

Page 22: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Lookup FunctionsLookup Functions

HLOOKUPHLOOKUP VLOOKUPVLOOKUP

Page 23: Computational Biology, Part 13 Spreadsheet Basics II Robert F. Murphy Copyright  1996, 1999, 2000, 2001. All rights reserved

Basic Spreadsheet FunctionsBasic Spreadsheet Functions

(Demonstration D1)(Demonstration D1) (Exercise C1)(Exercise C1)