SlideShare a Scribd company logo
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

More Related Content

What's hot

Some properties of m sequences over finite field fp
Some properties of m sequences over finite field fpSome properties of m sequences over finite field fp
Some properties of m sequences over finite field fp
IAEME Publication
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
Programming Homework Help
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
 
Function
Function Function
1 chapter1 introduction
1 chapter1 introduction1 chapter1 introduction
1 chapter1 introduction
SSE_AndyLi
 
Variational Bayes: A Gentle Introduction
Variational Bayes: A Gentle IntroductionVariational Bayes: A Gentle Introduction
Variational Bayes: A Gentle Introduction
Flavio Morelli
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Reading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGsReading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGs
Keisuke OTAKI
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
ramya marichamy
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
Ruo Ando
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
EasyStudy3
 
Numerical Methods 1
Numerical Methods 1Numerical Methods 1
Numerical Methods 1
Dr. Nirav Vyas
 
Expressiveness and Model of the Polymorphic λ Calculus
Expressiveness and Model of the Polymorphic λ CalculusExpressiveness and Model of the Polymorphic λ Calculus
Expressiveness and Model of the Polymorphic λ Calculus
evastsdsh
 
Elliptic Curves and Elliptic Curve Cryptography
Elliptic Curves and Elliptic Curve CryptographyElliptic Curves and Elliptic Curve Cryptography
Elliptic Curves and Elliptic Curve Cryptography
Md. Al-Amin Khandaker Nipu
 
lecture 4
lecture 4lecture 4
lecture 4sajinsc
 
Chemistry Assignment Help
Chemistry Assignment Help Chemistry Assignment Help
Chemistry Assignment Help
Edu Assignment Help
 

What's hot (20)

Some properties of m sequences over finite field fp
Some properties of m sequences over finite field fpSome properties of m sequences over finite field fp
Some properties of m sequences over finite field fp
 
Function and graphs
Function and graphsFunction and graphs
Function and graphs
 
lecture 1
lecture 1lecture 1
lecture 1
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
Function
Function Function
Function
 
1 chapter1 introduction
1 chapter1 introduction1 chapter1 introduction
1 chapter1 introduction
 
Variational Bayes: A Gentle Introduction
Variational Bayes: A Gentle IntroductionVariational Bayes: A Gentle Introduction
Variational Bayes: A Gentle Introduction
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Reading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGsReading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGs
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Numerical Methods 1
Numerical Methods 1Numerical Methods 1
Numerical Methods 1
 
Expressiveness and Model of the Polymorphic λ Calculus
Expressiveness and Model of the Polymorphic λ CalculusExpressiveness and Model of the Polymorphic λ Calculus
Expressiveness and Model of the Polymorphic λ Calculus
 
Elliptic Curves and Elliptic Curve Cryptography
Elliptic Curves and Elliptic Curve CryptographyElliptic Curves and Elliptic Curve Cryptography
Elliptic Curves and Elliptic Curve Cryptography
 
Lec4
Lec4Lec4
Lec4
 
lecture 4
lecture 4lecture 4
lecture 4
 
Chemistry Assignment Help
Chemistry Assignment Help Chemistry Assignment Help
Chemistry Assignment Help
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 

Similar to Lecture 4 f17

5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions
smiller5
 
Matlab lecture 6 – newton raphson method@taj copy
Matlab lecture 6 – newton raphson method@taj   copyMatlab lecture 6 – newton raphson method@taj   copy
Matlab lecture 6 – newton raphson method@taj copy
Tajim Md. Niamat Ullah Akhund
 
Master method
Master method Master method
Master method
Rajendran
 
Lecture 5_ Sorting and order statistics.pptx
Lecture 5_ Sorting and order statistics.pptxLecture 5_ Sorting and order statistics.pptx
Lecture 5_ Sorting and order statistics.pptx
JosephKariuki46
 
calculus-4c-1.pdf
calculus-4c-1.pdfcalculus-4c-1.pdf
calculus-4c-1.pdf
HUSSAINGHAZI1
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
daniloalbay1
 
Diaconis Ylvisaker 1985
Diaconis Ylvisaker 1985Diaconis Ylvisaker 1985
Diaconis Ylvisaker 1985
Julyan Arbel
 
Raices primitivas
Raices primitivasRaices primitivas
Raices primitivas
Rolando Vega
 
S1 - Process product optimization using design experiments and response surfa...
S1 - Process product optimization using design experiments and response surfa...S1 - Process product optimization using design experiments and response surfa...
S1 - Process product optimization using design experiments and response surfa...
CAChemE
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methods
Divya Bhatia
 
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program CorrectnessCMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
allyn joy calcaben
 
Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow AnalysisMiller Lee
 
Bounded solutions of certain (differential and first order
Bounded solutions of certain (differential and first orderBounded solutions of certain (differential and first order
Bounded solutions of certain (differential and first order
Alexander Decker
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
mathsjournal
 
lecture 11
lecture 11lecture 11
lecture 11sajinsc
 
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
 
Ijetr011954
Ijetr011954Ijetr011954
Ijetr011954
ER Publication.org
 
DeepLearn2022 1. Goals & AlgorithmDesign.pdf
DeepLearn2022 1. Goals & AlgorithmDesign.pdfDeepLearn2022 1. Goals & AlgorithmDesign.pdf
DeepLearn2022 1. Goals & AlgorithmDesign.pdf
Sean Meyn
 

Similar to Lecture 4 f17 (20)

5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions
 
Matlab lecture 6 – newton raphson method@taj copy
Matlab lecture 6 – newton raphson method@taj   copyMatlab lecture 6 – newton raphson method@taj   copy
Matlab lecture 6 – newton raphson method@taj copy
 
Master method
Master method Master method
Master method
 
Lecture 5_ Sorting and order statistics.pptx
Lecture 5_ Sorting and order statistics.pptxLecture 5_ Sorting and order statistics.pptx
Lecture 5_ Sorting and order statistics.pptx
 
calculus-4c-1.pdf
calculus-4c-1.pdfcalculus-4c-1.pdf
calculus-4c-1.pdf
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Diaconis Ylvisaker 1985
Diaconis Ylvisaker 1985Diaconis Ylvisaker 1985
Diaconis Ylvisaker 1985
 
Raices primitivas
Raices primitivasRaices primitivas
Raices primitivas
 
S1 - Process product optimization using design experiments and response surfa...
S1 - Process product optimization using design experiments and response surfa...S1 - Process product optimization using design experiments and response surfa...
S1 - Process product optimization using design experiments and response surfa...
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methods
 
L16
L16L16
L16
 
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program CorrectnessCMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
 
Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow Analysis
 
Bounded solutions of certain (differential and first order
Bounded solutions of certain (differential and first orderBounded solutions of certain (differential and first order
Bounded solutions of certain (differential and first order
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
Fractional Newton-Raphson Method and Some Variants for the Solution of Nonlin...
 
lecture 11
lecture 11lecture 11
lecture 11
 
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
 
Ijetr011954
Ijetr011954Ijetr011954
Ijetr011954
 
DeepLearn2022 1. Goals & AlgorithmDesign.pdf
DeepLearn2022 1. Goals & AlgorithmDesign.pdfDeepLearn2022 1. Goals & AlgorithmDesign.pdf
DeepLearn2022 1. Goals & AlgorithmDesign.pdf
 

Recently uploaded

weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 

Recently uploaded (20)

weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 

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