(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
Lecture 4 f17
1. Lecture 4—Intro Solving Non-Linear Equations (NLEs)
Outline
1 Introduction
The solution of a non-linear equation is a Root Finding Problem
2 Built-In Solution in Matlab: fzero
3 Built-In Solution in Excel: Solver
Enabling the solver
Using the solver
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 1 / 16
2. Features of a non-linear function
− 4 −2 0 2 4
−50
0
50 Roots
x
y
f(x) = −2x3
− x2
+ 20x + 1 Finding the roots of equations is one
of the most common numerical
tasks
Equations of state
Empirical relationships for friction
factors, heat transfer coefficients
Solution to complicated mass &
energy balances
>> p = [-2 -1 20 1 ]% Tell MATLAB about the polynomial
>> r = roots (p)
r =
-3.398872 2.948760 -0.049888
5 >> fplot ( @(x) polyval (p,x), [-4.5 4] , ’r’ );
>> plot ( [0 0 0], r, ’bo’,’markerface’,’blue’);
Command line:
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 2 / 16
3. Features of a non-linear function
−4 −2 0 2 4
−50
0
50
∂f
∂x
= 0 ∂2
f
∂x2 > 0
∂f
∂x
= 0 ∂2
f
∂x2 < 0
Extrema
x
y
f(x) = −2x3
− x2
+ 20x + 1 Optimization methods allow the
maxima or minima of a function to
be located
Applications:
Minimize the cost of a process by
adjusting its parameters
Maximize the yield or selectivity of
a reaction by adjusting tempera-
ture/pressure/concentration
>> p = [-2 -1 20 1 ]% Tell MATLAB about the polynomial
>> r = roots (p)
r =
-3.398872 2.948760 -0.049888
5 >> fplot ( @(x) polyval (p,x), [-4.5 4] , ’r’ );
>> plot ( [0 0 0], r, ’bo’,’markerface’,’blue’);
Command line:
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 2 / 16
4. Matlab built-in support for polynomials
Matlab has a number of functions to help with polynomials. These functions all use a
coefficient array to describe the polynomial:
Math
P1(x) = −2x3
− x2
+ 20x + 1
P2(x) = x4
− x2
+ 2x
Matlab Coefficient Array
>> p1 = [ -2, -1, 20, 1 ];
>> p2 = [ 1, 0, -1, 2, 0 ];
Command line:
The order n of a polynomial is its largest exponent.
The coefficient array has a total of n + 1 elements.
The first element of the coefficient array is the coefficient of the highest power
(called the order) of the polynomial.
The last element is the value of the constant.
Matlab functions that deal with polynomials:
y = polyval(p, x) Evaluate polynomial p at x
r = roots(p) Return array of all n roots (real + complex) of p.
p = polyfit(x,y,n) Fit data y vs. x to a polynomial of order n. x and y
must have the same length, which must be at least
n + 1. For example n = 1 is just a line, and you need
at least 2 points to define a line.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 3 / 16
5. Solving for the root — Where to start?
Transforming the equation
Consider the Redlich-Kwong Equation of State
P =
RT
V − b
−
a
V(V + b)
√
T
42 44 46 48 50
0
2
4
6
·105
V, cm3
mol
P,bar
T = 60o C
methyl chloride
This function has no real roots
P ≤ 0 is not a physical pressure
We are usually interested in the
V (at a given T) that gives us a
certain P
How is this a root-finding
problem?
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 4 / 16
6. Solving for the root — Where to start?
Transforming the equation
Consider the Redlich-Kwong Equation of State
1 =
RT
V − b
−
a
V(V + b)
√
T
42 44 46 48 50
0
2
4
6
·105
V, cm3
mol
P,bar
T = 60o C
methyl chloride
Suppose we want to know the
V corresponding to P = 1 bar
We can substitute this choice
into the equation.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 4 / 16
7. Solving for the root — Where to start?
Transforming the equation
Consider the Redlich-Kwong Equation of State
1 −
RT
V − b
−
a
V(V + b)
√
T
= 0
0.2 0.4 0.6 0.8 1
·105
0
0.5
V, cm3
mol
1−P,bar
T = 60o C
methyl chloride
Now rearrange the equation so
that the RHS is zero.
The resulting equality is only
true when the right V is
selected
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 4 / 16
8. Solving for the root — Where to start?
Transforming the equation
Consider the Redlich-Kwong Equation of State
1 −
RT
V − b
−
a
V(V + b)
√
T
= f(V)
0.2 0.4 0.6 0.8 1
·105
0
0.5
V, cm3
mol
1−P,bar
T = 60o C
methyl chloride
Now rearrange the equation so
that the RHS is zero.
The resulting equality is only
true when the right V is
selected
As V is varied the right-hand
side varies.
f(V) is a transformed form of
the RK EOS
f(V) = 0 is the solution to our
problem
We can see from the plot that
the correct molar volume is
near 30,000 cm3
mol
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 4 / 16
9. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
10. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
In general, root-finding methods apply when we have an equality
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
11. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
In general, root-finding methods apply when we have an equality
1 with 1 unknown x
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
12. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
In general, root-finding methods apply when we have an equality
1 with 1 unknown x
2 and any number of specified parameters {pi}:
left(x, {pi}) = right(x, {pi}) (1)
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
13. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
In general, root-finding methods apply when we have an equality
1 with 1 unknown x
2 and any number of specified parameters {pi}:
left(x, {pi}) = right(x, {pi}) (1)
We can form a function f(x, {pi}):
f(x, {pi}) = left(x, {pi}) − right(x, {pi})
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
14. Solving for the root — Where to start?
Transforming the equation into its root-finding form
First Step — Form the ‘‘Root-finding function’’
Any equality with 1 unknown can be transformed into a function whose
roots satisfy the equality
In general, root-finding methods apply when we have an equality
1 with 1 unknown x
2 and any number of specified parameters {pi}:
left(x, {pi}) = right(x, {pi}) (1)
We can form a function f(x, {pi}):
f(x, {pi}) = left(x, {pi}) − right(x, {pi})
The roots of f correspond to solutions of (1). f(V) is the root-finding function.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 5 / 16
15. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
16. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
17. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
18. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
p3 = b 0.08664 R Tc
Pc
= 44.8909
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
19. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
p3 = b 0.08664 R Tc
Pc
= 44.8909
p4 = T 60 o
C
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
20. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
p3 = b 0.08664 R Tc
Pc
= 44.8909
p4 = T 60 o
C
p5 = P 1 bar
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
21. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
p3 = b 0.08664 R Tc
Pc
= 44.8909
p4 = T 60 o
C
p5 = P 1 bar
x = V
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
22. Solving for the root — Where to start?
Transforming the equation
Example
P =
RT
V − b
−
a
V(V + b)
√
T
Find V such that P = 1 atm and T = 60o
C
What are {pi } (the fixed parameters)?
p1 = R 83.14
p2 = a
0.4274 R2 T2.5
c
Pc
= 1.5641 × 108
p3 = b 0.08664 R Tc
Pc
= 44.8909
p4 = T 60 o
C
p5 = P 1 bar
x = V
f(V, {R; a; b; T; P}) = 1 −
RT
V − b
−
a
V(V + b)
√
T
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 6 / 16
23. fzero — The Matlab tool for solving Non-Linear equations
A typical problem
Find the molar volume of methyl chloride vapor such that at T = 60 ◦C the pressure is 1 bar.
Use the Redlich-Kwong Equation of State:
P =
RT
V − b
−
a
V(V + b)
√
T
Variable Value Unit
a 0.42748R2
Tc
2.5
Pc
cm6
·bar·K0.5
mol2
b 0.08664RTc
Pc
cm3
mol
R 83.14 cm3
·bar
mol·K
Tc 416.15 K
Pc 66.8 bar
Quick Solution with Matlab
Define the parameters. Note how the pressure is defined as a function_handle.
>> Pc = 66.8; Tc = 416.15; R = 83.14;
>> a = 0.42748 .* R^2 .* Tc .^ 2.5 ./ Pc;
>> b = 0.08664 .* R .* Tc ./ Pc;
>> T = 60 + 273.15;
5 >> P = @(V) R .* T ./ (V-b) - a ./ (V .* (V+b) .* sqrt(T));
>> root_finding_equation = @(V) 1 - P(V);
>> V = fzero( root_finding_equation, 30000 )
V = 27431.8744533891
Script-file: find_methyl_chloride_P.m
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 7 / 16
24. fzero — The Matlab tool for solving Non-Linear equations
A typical problem
Find the molar volume of methyl chloride vapor such that at T = 60 ◦C the pressure is 1 bar.
Use the Redlich-Kwong Equation of State:
P =
RT
V − b
−
a
V(V + b)
√
T
Variable Value Unit
a 0.42748R2
Tc
2.5
Pc
cm6
·bar·K0.5
mol2
b 0.08664RTc
Pc
cm3
mol
R 83.14 cm3
·bar
mol·K
Tc 416.15 K
Pc 66.8 bar
Quick Solution with Matlab
This is the important part! This function_handle will have a value of zero when the
correct molar volume is found.
>> Pc = 66.8; Tc = 416.15; R = 83.14;
>> a = 0.42748 .* R^2 .* Tc .^ 2.5 ./ Pc;
>> b = 0.08664 .* R .* Tc ./ Pc;
>> T = 60 + 273.15;
5 >> P = @(V) R .* T ./ (V-b) - a ./ (V .* (V+b) .* sqrt(T));
>> root_finding_equation = @(V) 1 - P(V);
>> V = fzero( root_finding_equation, 30000 )
V = 27431.8744533891
Script-file: find_methyl_chloride_P.m
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 7 / 16
25. fzero — The Matlab tool for solving Non-Linear equations
Quick Solution with Matlab
Now we solve for V numerically. fzero takes two arguments.
(1) The first is a function_handle that accepts exactly 1 argument.
(2) The second argument is an initial guess.
Why did I use 30000 for the initial guess? A few slides ago I plotted this function and
noted visually that the correct molar volume was around 30,000 cm3
mol
.
I just used fzero in OPEN mode. I’m telling Matlab to look near 30,000 cm3
mol
but I
place no restrictions on what range of molar volumes to try.
>> Pc = 66.8; Tc = 416.15; R = 83.14;
>> a = 0.42748 .* R^2 .* Tc .^ 2.5 ./ Pc;
>> b = 0.08664 .* R .* Tc ./ Pc;
>> T = 60 + 273.15;
5 >> P = @(V) R .* T ./ (V-b) - a ./ (V .* (V+b) .* sqrt(T));
>> root_finding_equation = @(V) 1 - P(V);
>> V = fzero( root_finding_equation, 30000 )
V = 27431.8744533891
Script-file: find_methyl_chloride_P.m
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 7 / 16
26. fzero — The Matlab tool for solving Non-Linear equations
Quick Solution with Matlab
Why did I use 30000 for the initial guess? A few slides ago I plotted this function and
noted visually that the correct molar volume was around 30,000 cm3
mol
.
I just used fzero in OPEN mode. I’m telling Matlab to look near 30,000 cm3
mol
but I
place no restrictions on what range of molar volumes to try.
We can also use fzero in CLOSED mode.
The initial guess I provided is a 2-element array.
It tells Matlab:
‘‘The root_finding_equation has a value of zero
somewhere between 20000 and 40000’’
>> Pc = 66.8; Tc = 416.15; R = 83.14;
>> a = 0.42748 .* R^2 .* Tc .^ 2.5 ./ Pc;
>> b = 0.08664 .* R .* Tc ./ Pc;
>> T = 60 + 273.15;
5 >> P = @(V) R .* T ./ (V-b) - a ./ (V .* (V+b) .* sqrt(T));
>> root_finding_equation = @(V) 1 - P(V);
>> V = fzero( root_finding_equation, [20000 40000] )
V = 27431.8744533891
Script-file: find_methyl_chloride_P.m
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 7 / 16
27. fzero — The Matlab tool for solving Non-Linear equations
Quick Solution with Matlab
We can also use fzero in CLOSED mode.
The initial guess I provided is a 2-element array.
It tells Matlab:
‘‘The root_finding_equation has a value of zero
somewhere between 20000 and 40000’’
If I’m wrong and root_finding_equation does not in fact have a zero in this
interval I’ll get an error
>> Pc = 66.8; Tc = 416.15; R = 83.14;
>> a = 0.42748 .* R^2 .* Tc .^ 2.5 ./ Pc;
>> b = 0.08664 .* R .* Tc ./ Pc;
>> T = 60 + 273.15;
5 >> P = @(V) R .* T ./ (V-b) - a ./ (V .* (V+b) .* sqrt(T));
>> root_finding_equation = @(V) 1 - P(V);
>> V = fzero( root_finding_equation, [20000 25000] )
??? Error using fzero (line 274)
??? The function values at the interval endpoints must differ in sign.
Script-file: find_methyl_chloride_P.m
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 7 / 16
28. Outline
1 Introduction
The solution of a non-linear equation is a Root Finding Problem
2 Built-In Solution in Matlab: fzero
3 Built-In Solution in Excel: Solver
Enabling the solver
Using the solver
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 8 / 16
29. Solving non-linear equations in Excel
Excel has a tool called Solver that can perform two different tasks
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 9 / 16
30. Solving non-linear equations in Excel
Excel has a tool called Solver that can perform two different tasks
1 Set the value of a cell to a particular value by changing other cells.
This is what we’re interested in right now.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 9 / 16
31. Solving non-linear equations in Excel
Excel has a tool called Solver that can perform two different tasks
1 Set the value of a cell to a particular value by changing other cells.
This is what we’re interested in right now.
2 Minimize/maximize the value of a cell by changing other cells.
We will come back to this one later.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 9 / 16
32. Solving non-linear equations in Excel
Excel has a tool called Solver that can perform two different tasks
1 Set the value of a cell to a particular value by changing other cells.
This is what we’re interested in right now.
2 Minimize/maximize the value of a cell by changing other cells.
We will come back to this one later.
The Solver Add-In is not enabled by default, although on College
of Engineering machines this has usually been done by the system
administrator.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 9 / 16
33. Solving non-linear equations in Excel
Excel has a tool called Solver that can perform two different tasks
1 Set the value of a cell to a particular value by changing other cells.
This is what we’re interested in right now.
2 Minimize/maximize the value of a cell by changing other cells.
We will come back to this one later.
The Solver Add-In is not enabled by default, although on College
of Engineering machines this has usually been done by the system
administrator.
If you don’t see the following under the Data tab in Excel, then the
next few slides show you how to get it.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 9 / 16
34. Enable the Solver Add-In
Go to the File tab and select Options
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 10 / 16
35. Enable the Solver Add-In
In the dialog that appears, select Add-Ins
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 10 / 16
36. Enable the Solver Add-In
In the next dialog, ensure that the Manage: box is showing Excel
Add-ins and select Go...
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 10 / 16
37. Enable the Solver Add-In
In the next dialog, ensure that Solver Add-in is checked and then
click OK
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 10 / 16
38. Outline
1 Introduction
The solution of a non-linear equation is a Root Finding Problem
2 Built-In Solution in Matlab: fzero
3 Built-In Solution in Excel: Solver
Enabling the solver
Using the solver
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 11 / 16
39. Using Solver to Solve Non-linear equations
A typical problem
Find the molar volume of methyl chloride vapor such that at T = 60 ◦C the pressure is 1 bar.
Use the Redlich-Kwong Equation of State:
P =
RT
V − b
−
a
V(V + b)
√
T
Variable Value Unit
a 0.42748R2
Tc
2.5
Pc
cm6
·bar·K0.5
mol2
b 0.08664RTc
Pc
cm3
mol
R 83.14 cm3
·bar
mol·K
Tc 416.15 K
Pc 66.8 bar
Here’s a good start to solving the problem. The way I’ve set this spreadsheet up so far
has a few features I’d like to point out.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 12 / 16
40. Good practice with spreadsheets
Formatting is important! Ask anyone who’s had to share a spreadsheet with their boss.
Make what you’re doing clear!
Use variable names
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 13 / 16
41. Good practice with spreadsheets
Formatting is important! Ask anyone who’s had to share a spreadsheet with their boss.
Make what you’re doing clear!
Use variable names
Use superscripts and subscripts and the Symbol font to make variable names
appear as close to their mathematical representation as possible.
The keyboard shortcut CTRL + 1 is worth leaning to make this chore easier.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 13 / 16
42. Good practice with spreadsheets
Formatting is important! Ask anyone who’s had to share a spreadsheet with their boss.
Make what you’re doing clear!
Use variable names
Use superscripts and subscripts and the Symbol font to make variable names
appear as close to their mathematical representation as possible.
The keyboard shortcut CTRL + 1 is worth leaning to make this chore easier.
Keep parameters (constants) separate from values that you will be changing
frequently.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 13 / 16
43. Good practice with spreadsheets
Formatting is important! Ask anyone who’s had to share a spreadsheet with their boss.
Make what you’re doing clear!
Use variable names
Use superscripts and subscripts and the Symbol font to make variable names
appear as close to their mathematical representation as possible.
The keyboard shortcut CTRL + 1 is worth leaning to make this chore easier.
Keep parameters (constants) separate from values that you will be changing
frequently.
Keep calculated values distinguished from user-manipulated values. In this
example values I entered manually Are in an easily recognized font.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 13 / 16
44. Good practice with spreadsheets
Formatting is important! Ask anyone who’s had to share a spreadsheet with their boss.
Make what you’re doing clear!
Use variable names
Use superscripts and subscripts and the Symbol font to make variable names
appear as close to their mathematical representation as possible.
The keyboard shortcut CTRL + 1 is worth leaning to make this chore easier.
Keep parameters (constants) separate from values that you will be changing
frequently.
Keep calculated values distinguished from user-manipulated values. In this
example values I entered manually Are in an easily recognized font.
Include units!! Again, take the time to use superscripts.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 13 / 16
45. Good practice with spreadsheets
Use Names to Make Formulas Readable
Make what you’re doing clear!
The box to the left of the formula bar is for giving cells human-friendly names.
Use it!
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 14 / 16
46. Good practice with spreadsheets
Use Names to Make Formulas Readable
Make what you’re doing clear!
The box to the left of the formula bar is for giving cells human-friendly names.
Use it!
Some names (like R) can’t be used. I usually append an underscore _ when
this is the case.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 14 / 16
47. Good practice with spreadsheets
Use Names to Make Formulas Readable
Make what you’re doing clear!
The box to the left of the formula bar is for giving cells human-friendly names.
Use it!
Some names (like R) can’t be used. I usually append an underscore _ when
this is the case.
For variables with numerical subscripts, e.g., T1, enter the name as T_1.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 14 / 16
48. Good practice with spreadsheets
Use Names to Make Formulas Readable
Make what you’re doing clear!
The box to the left of the formula bar is for giving cells human-friendly names.
Use it!
Some names (like R) can’t be used. I usually append an underscore _ when
this is the case.
For variables with numerical subscripts, e.g., T1, enter the name as T_1.
Look at how nice my formula for a is to read, it gives you a warm and fuzzy
feeling doesn’t it?
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 14 / 16
49. Good practice with spreadsheets
Use Names to Make Formulas Readable
Make what you’re doing clear!
The box to the left of the formula bar is for giving cells human-friendly names.
Use it!
Some names (like R) can’t be used. I usually append an underscore _ when
this is the case.
For variables with numerical subscripts, e.g., T1, enter the name as T_1.
Similarly, I can also tell by looking at the cell formula that this is the RK
Equation of State.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 14 / 16
50. Setting up the problem for Solver
Now I’m going to define my root-finding cell.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 15 / 16
51. Setting up the problem for Solver
Now I’m going to define my root-finding cell.
And now open up the Solver (it’s in the Data tab).
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 15 / 16
52. The Solver dialog.
The Solver dialog has a lot going on inside of it. For now, we only
need to use the top three rows.
Set Objective This is the address of the cell you want to solve for.
We want the Difference: cell to assume a value of 0.
Click that cell and its address will appear in the Set
Objective box.
To: Here is where we decide between root-finding (Value
of:) and min/max problems.
We want the difference between the actual pressure
and 1 bar to be 0, so Value of: should be selected
with a value of 0 in the box.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 16 / 16
53. The Solver dialog.
Now tell Solver which cells to manipulate in order to make the
difference 0. Click on the Range Selector Tool
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 16 / 16
54. The Solver dialog.
We want to change the molar volume. Click it
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 16 / 16
55. The Solver dialog.
We’re ready! Click Solve
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 16 / 16
56. The Solver dialog.
All done. Notice the volume has changed to 27431.9, and the
Difference: is 8.48e-07. Pretty close to zero. If that’s not close
enough, we can tweak the tolerance in the Solver.
Che 310 | Chapra 5.1–5.2 | Intro to Root-Finding 4 — Intro to NLEs September 19, 2017 16 / 16