Null 1
Null 1
Engineering
CHEN10050
2020/21
CHEN10050 Excel Basics for Engineering 2020/21
Topics covered:
• Data input and manipulation
• Built-in and user-defined functions
• Data plotting
• Roots of equations using the Solver/GoalSeek tools
• Linear and non-linear regression with plots and the Solver tool
1
CHEN10050 Excel Basics for Engineering 2020/21
1 Spreadsheeting Exercises
1.1 Introduction
A spreadsheeting package such as Microsoft Excel can help you with many aspects of your course.
Amongst other things, it can organise data, perform calculations and draw graphs for use in reports.
The exercises illustrate some of the things that might prove useful in connection with, say, your maths,
laboratory and project courses.
Save your files on MyDocuments or anywhere you can easily access the files because during
the online assessment you will allowed to use them to solve the exercises.
You are reminded that work submitted for assessment must be the result of your own efforts.
• Keep column headings concise - use multiple rows rather than wide columns. As an alternative,
Excel has ways of rotating text and wrapping it to fit available column width. Right click on the cell,
choose Format cells.., then Alignment to see the options available.
• Do not use too many decimal places in number formats.
• Use the Format, Column, Autofit selection sequence of menu bar commands (Page Layout) to match
column widths to column contents. Beware of the effect of long titles. Restrict the fit to particular cells
by highlighting them. Long titles in a single cell of the column will automatically overflow into adjacent
empty cells.
• Arrange the information flow to be vertical rather than horizontal. Page breaks are more natural that
way.
• Always use the Preview facility to check that the results are what you expect.
• Include your name on each page of output. This makes it easier to find your output among lots of
other similar output. You can use a Header or Footer (a bit of text that automatically appears at the
top or bottom of every page) for this purpose. (In Excel, see Page Layout, and click on the small
arrow on the right of “Sheet Options”.)
1.4 Cells
2
CHEN10050 Excel Basics for Engineering 2020/21
Tab
Cell column
Active cell letter
border Formula Bar
HELP
button
Button
Active cell
Cell row
numbers
Enter the values 1, 2, 3 in cells A1, A2, A3. Enter 4, 5, 6 in the next column alongside, then 7, 8, 9 in
the next column.
Cell addresses are used to help manipulate data, perform calculations etc. You can use lower case
letters in cell addresses. Cell b2 means the same as cell B2.
Cell B2 should contain the value 5. To illustrate the use of cell addresses, type =b2 in cell B8, then
press Enter. Note that the formula appears in the formula bar at the top of the screen as you type. Cell
B8 now contains the value 5.
Activate cell B8 by clicking on it. The formula =B2 is displayed in the formula bar as illustrated in Figure
2.
The active cell has a bold border with a button in the bottom right hand corner. If you click on the border
and move it to another cell the whole contents of the cell moves. If you click on the button and move
that, the instructions in the cell are extended into the highlighted cells.
Use the button on the border of cell B8 to extend the highlighted area into cell B9 – that is, down one
cell. Now click on cell B9 and observe that it contains the formula =b3. A cell address written as B2 is
a relative address. If you drag it down one row it will change to B3. Repeat the exercise by dragging
cell B8 right into cell C8, then click on cell C8 and observe that it contains the formula =C2. Confirm
that dragging cell B8 up one cell produces the formula =B1 in cell B7, and that dragging it left produces
=A2 in cell A8.
The Edit..Copy and Edit..Paste menu commands can also be used to copy cell B8 up, down, left and
right one cell. The results are identical to using the button.
The column or the row or both in a cell address can be fixed by putting a $ in front of it. To illustrate the
effect of fixing the column, enter =$B2 in cell B12. Then drag cell B12 into the adjacent vertical and
horizontal cells. Compare the results with what you did previously. Introducing the $ sign forces absolute
addressing of the column. The part(s) of the cell address preceded by the $ do not change if you copy
the cell to another location.
3
CHEN10050 Excel Basics for Engineering 2020/21
Now try fixing the row part of the cell address by typing =B$2 in cell B16 and copying that cell to adjacent
ones.
Finally, fix both row and cell by typing =$B$2 in cell B20 and copy that one into the adjacent cells too.
Review all your results. Introducing the $ sign forces absolute addressing of the column, row or both.
The part(s) of the cell address preceded by the $ do not change if you copy the cell to another location.
It is very important to understand the correct use of cell addresses.
If you are unfamiliar with the 2007 version of Office, you can always use the question mark button on
the top left of the window (HELP button).
Save the spreadsheet as file P:\ex1.xls using the File..Save As... feature from the menu bar. Excel
will automatically add the file name extension .xls. DO NOT type the .xls in the filename.
1.5.1.1 Technique
Use the symbol ^ in a formula to raise to a power.
To use sub- or superscripts, highlight the relevant part of the text, then right click and use the Format
cells.., Alignment options.
To adjust spreadsheet column widths, double click on the dividing lines in the column headings.
4
CHEN10050 Excel Basics for Engineering 2020/21
5
CHEN10050 Excel Basics for Engineering 2020/21
The plot appears in the same window (see Figure 4). Right click on the plot area to add labels to the
axis and change the graph characteristics.
Figure 4: Plot
1.5.2.2 Technique
You can type PI() in a formula to obtain an accurate value for (see Functions below).
6
CHEN10050 Excel Basics for Engineering 2020/21
To get multiple lines of text in a single cell (or group of cells), select the cell(s), right click and use Format
cells.
To use sub- or superscripts, highlight the relevant part of the text, then right click and use the Format
cells.., Alignment options. In axis labels, use Format axis title similarly.
Text size can be changed by right clicking then adjusting the font size.
d/2
d/2
Length
in y
direction
d/2
d/2
Length in x direction
Information Technology
7
CHEN10050 Excel Basics for Engineering 2020/21
Tank diameter, d m
Tank height, h m
Number of tanks Number of Tank farm area Total usable tank
2
in x direction tanks A, m capacity
p in y direction Vtotal, m3
q
4 4
4 7
4 8
4 9
4 10
1.6 Functions
Excel contains many built-in functions. You can see a list by clicking on Formula on the tab and then
click on “Insert Function” on the top left part of the screen as shown in Figure 6. The exercises in this
section illustrate the use of some of these functions.
Figure 6: Functions
• Create a table of values, including column titles. The first column should contain the angles 0, 15,
30, ... , 360. You do not need to type all these values individually. First type a title (for example,
Angle, degrees) in cell A1. Type 0 in cell A2, then 15 in cell A3. Highlight cells A2 to A3. Drag the
highlighted cells down using the button and observe that final value is displayed as you do so. Keep
dragging until the final value is 360. Excel assumed that you wanted to create a series of numbers
incrementing by 15.
8
CHEN10050 Excel Basics for Engineering 2020/21
• The trigonometric functions only work for angles in radians, not degrees. A conversion function is
available. If the first cell in your list of angles is cell A2, enter =radians(A2) alongside it in cell B2.
Put an appropriate title in cell B1.
• Select cell C2. Type = then click the “Insert Functions” button in the Formulas box in the tab. Type
“sin” then click on go. Figure 7 shows what happens next (only one row of the table is shown)
• Click the button shown in Figure 7. A small selection window will appear. Highlight cell B3 to indicate
that is what you want to take sin of. Press OK to complete the selection.
• Make an XY plot of sin versus angle in degrees.
• Highlight all 25 rows of numerical data in column A. Press the Ctrl key and highlight the same 25
rows of column C. Both column A and column C should now be highlighted.
• Click on “Insert” in the tab.
• Choose the Scatter in the chart option, then the variant that plots smoothed lines.
• Click on “Select Data” on the tab, select “Series 1” and then “edit”. Name the series as sin. (see
Figure 8)
• Add the labels for the x axis (Angle/degree) and the y-axis (Function value) and the plot title (SIN
function), clicking on “Chart Layouts”.
Extend the table to include cos and tan. Make the chart display sin, cos and tan simultaneously as
separate series. Do NOT produce three separate charts. Click again on “Select Data” and click on “Add”
button.
Add the title of the new series of data. To enter the data click the 2nd button (for X values). Another pop-
up appears. Highlight the data in cells A2 to A26 then press the coloured button to return to Figure 8.
Click the 3rd selection button to choose cells D2:D26 as the Y values. You could use the 1st selection
button to get the series name from cell D1 in a similar way – but it might be just as easy to type cos in
the box.
Note the way Excel refers to a range of cells. D2:D26 means all the cells starting from D2 up to and
including D26. (Similarly H1:K15 would refer to a whole oblong block of cells with H1 at top left and K15
at bottom right.)
9
CHEN10050 Excel Basics for Engineering 2020/21
Graphing tan creates problems because it gets very large as the angle approaches 90 (and 270)
degrees, then becomes very large and negative as the angle increases beyond 90 (and 270) degrees.
Adding tan into the plot as a single series is NOT satisfactory.
Change the y-axis scale to ± 3 so that the sin and cos curves are clearly visible. Do this by right clicking
on the y-axis and navigating through the menus that appear.
Tidy up the plot by setting an appropriate x-axis scale, tick marks at 15 degree intervals on the x-axis
and 0.1 intervals on the y-axis, etc.
Tidy up the table by arranging that it displays radians, sin, cos and tan to four decimal places. To do
this, highlight the relevant columns, right click and choose Format cells…, Number… then choose
Number and set decimal places to 4 on the form that appears.
10
CHEN10050 Excel Basics for Engineering 2020/21
In the Developer tab of Excel’s ribbon, select Visual Basic to open the function editor. Next, in the menu
bar of the new window, select Insert→Module. The custom function should be typed in the new window
that will pop-up and should have the following structure:
Function function_name(argument1, argument2, …)
function_name = mathematical_expression
End Function
For example, the function called myfunction expressed mathematically as ax2+bx+c has as the
arguments a, b, c and x, and should be written as:
Function myfunction(x, a, b, c)
myfunction = a*x^2+b*x+c
End Function
11
CHEN10050 Excel Basics for Engineering 2020/21
Close the editor window and test the function in Excel. The myfunction function can now be used as
any Excel predefined function by typing myfunction() in a cell of the spreadsheet. Try plotting the custom
function for different values of x and for constant values of a b and c, as shown in Figure 11.
Important note: Workbooks that contain custom functions should be saved as Excel Macro-Enabled
Workbooks to work properly once they are re-opened. These files have extension .xlsm.
Goal Seek is efficient but not very powerful; to find the root of the equation and needs to have a target
cell that is close to the actual root of the equation. Therefore, plot the function in a range of data (for
example in Figure 9 from 1.5 to 4) and identify the three roots. Click on the Data tab and on “What-If-
analysis” and then fill the form of Goal Seek. The Set Cell in the example case is C5 since this contains
the function expression. We want it set equal to zero by varying the value in cell B5. Click Ok. The
12
CHEN10050 Excel Basics for Engineering 2020/21
estimate of the root and the corresponding value of f(x) should replace the original values. Repeat this
procedure for all the roots of your equation. This means you should know in advance how many roots
your equation has!
13
CHEN10050 Excel Basics for Engineering 2020/21
Temperature, T Pressure, P
C mm Hg
-36.7 1
-19.6 5
-11.5 10
-2.6 20
7.6 40
15.4 60
26.1 100
42.2 200
60.6 400
80.1 760
P = a 0 + a1T + a 2T 2 + ... + a mT m
of order m = 3 and m = 4 to the data of Table 2. Display the trendline equations in scientific notation
with six decimal places. (For example, 0.000123456 should be displayed as 0.123456E-03).
Note: by default Excel gives the trendline equation as y = f(x), and you should always edit the
equations to use the correct symbols, in this case P = f(T).
Use the trendline equations in the spreadsheet to re-calculate estimates Pestimate of P in each case.
Display the estimated pressures to 2 decimal places. Hence calculate the relative percentage error in
the estimated values ((Pestimate-P)*100/P), display to three decimal places).
1.8.1.1 Technique
Figure 13 shows part of the spreadsheet.
Use the Help facility to obtain an explanation of trendline equations and the meaning of R 2.
Right click on the data points on the chart to obtain the trendline option. Within the trendline dialogue,
choose the options to display the equation and R 2 value on the chart.
When the trendline equation is displayed, right click on it and format the labels to display in scientific
format with 6 decimal places.
You can copy coefficient values from the displayed equation into spreadsheet cells using Edit..Copy,
Edit..Paste. Take care not to lose the sign when copying negative values.
14
CHEN10050 Excel Basics for Engineering 2020/21
When you have a set a data that you want to fit with a specific equation (derived from a theory for
example), there is another tool of Excel called Solver that can help you. Solver works with a group of
cells that are related to the formula in the target cell. Solver adjusts the values in the changing cells that
you specify — called the adjustable cells — to produce the result that you specify from the objective
cell formula.
First of all check that Solver has been installed in your computer. Click on the Data tab, Solver should
be on the Analysis group (Figure 14). (If Solver does not appear in the Analysis group, you need to add
the solver Add-in program. Click the File tab, and then click Options, click Add-Ins, and then in the
Manage box, select Excel Add-ins. Click Go.)
So if you want to fit your data against the Clausius-Clapeyron equation (eq. 1), Solver can be used to
adjust the values of A and B
B
log10 P = A − (eq. 1)
(T + 273 .15 )
to the vapour pressure data of Table 2. To do this, you need to minimise the sum of squares of the error
(SSE) between the data and the fitted equation. For a set of estimated values ŷ i of data points y i , i =
1,…,n.
n
SSE = ( yi − yˆi )
2
i =1
15
CHEN10050 Excel Basics for Engineering 2020/21
SSEmean − SSE
R2 =
SSEmean
where SSEmean is the total sum of the squares of the residuals between the data points and its mean
value, y , defined as
n
1 n
SSEmean = ( yi − y ) and y = yi
2
i =1 n i =1
The coefficient of determination can be interpreted as a normalized measure of how good the fitting
expression is in describing the variability of the data in opposition to simply assuming the mean value
of the data. For a perfect fit, SSE = 0 giving a value of R = 1 . When the fitting expression does not
2
1.8.2.1 Technique
Figure 11 shows part of the spreadsheet.
Enter the raw data and calculate log 10P.
Enter the first guesses for constants A and B in two spreadsheet cells. Calculate the corresponding
estimates of log10P given by the Clausius-Clapeyron equation.
16
CHEN10050 Excel Basics for Engineering 2020/21
SSEmean can be calculated in the same way as SSE by entering the formula =SUM((E12:E21-
AVERAGE(E12:E21))^2) and pressing Ctrl+Shift+Enter.
17