Sie sind auf Seite 1von 10

ENME332
–
2010.02.

02
 
 1



Nonlinear
Equations:
Solution
Advice
for
ENME332
Students

There
are
basically
four
ways
to
solve
a
nonlinear
equation:

1. Use
MATLAB
or
your
graphing
calculator.

2. Use
a
textbook
root‐finding
algorithm,
such
as
Newton's
Method
or
the

Secant
Method.

3. Use
a
problem‐specific
method.

4. Plug
in
numbers
until
you
get
a
number
that's
close
enough.

The
first
is
the
quickest,
if
it
works;
the
last
is
the
most
likely
to
work,
but
the
most

tedious.
Whatever
method
you
use,
before
enshrining
it
in
your
notebook,
do
check

that
it
is:

A. Actually
a
solution
(plug
into
the
equation
in
your
notebook
to
see
if
it
is
an

equality),
and

B. Reasonable
(is
it
a
real
number?
is
it
below
0
K?
is
it
above
0
K,
but
colder

than
physically
possible?
Is
it
hotter
than
physically
possible?)

Below
I
give
some
simple
instructions
with
respect
to
each
method.
These
appear
to

work
on
Theme
Problem
3
in
the
homework,
but
I
cannot
make
guarantees
for

every
problem
we
may
encounter
in
the
class
(or
in
life).
Please
use
your
judgment.


1.
Automatic
Solvers

In
the
modern
day,
most
college
students
have
sophisticated
graphing
calculators

and
computers.
Some
of
these
computers
have
mathematics
applications
on
them;

one
such
application
is
MATLAB.
The
following
are
basic
directions
for
solving

equations
using
the
three
tools
you
are
most
likely
to
have
ready
to
hand:
TI‐83‐
series
calculators,
TI‐89‐series
calculators
(and
the
similar
TI‐92‐series

calculators/small
computers),
and
MATLAB.


Solving
on
the
TI‐83

The
TI‐83
has
one
numerical
solver
built‐in,
to
be
accessed
as
follows:

1. Press
the
[MATH]
key
to
open
the
mathematics
menu.

2. Select
the
last
option:
“0:
Solver…”.

3. Use
the
cursor
to
select
the
equation
(the
line
beginning
“0
=”).

4. Type
the
equation,
using
the
variable
X
as
your
unknown.
You
may
have
to

rearrange
to
place
it
in
the
correct
format.
Press
the
[ENTER]
key
to
store.

5. Type
your
initial
guess
based
on
your
physical
intuition.

6. (Optional)
Adjust
the
permissible
range,
listed
as
two
numbers
between

curly
braces.
The
default
is
{-1e99,1e99}
–
for
problems
in
this
class,
aim

to
make
a
range
wide
enough
to
include
the
correct
answer,
but
narrow

enough
to
exclude
the
impossible.

When
this
is
done,
press
the
[2nd]
key
and
then
the
button
with
[SOLVE]
written

above
it.
This
will
replace
your
guess
with
the
solution.

ENME332
–
2010.02.02
 
 2



Solving
on
the
TI‐89

There
are
two
functions
on
the
TI‐89
to
solve
numerical
equations:
solve
and

nSolve.
Both
take
input
in
the
same
format:
the
equation,
written
algebraically

with
your
unknown
as
a
variable
name,
and
your
unknown,
the
variable
name
used

in
the
equation.
The
easiest
method
is:

1. Select
the
“Algebra”
menu
(F2).

2. Select
the
first
option
(“1:solve(“)
or
the
eighth
(“8:nSolve(“),
and

press
[ENTER].
This
will
put
the
function
call
on
the
command
line.

3. Enter
your
equation
with
a
variable
name
(such
as
“t”)
for
the
unknown
and

numbers
otherwise.
Include
both
sides
and
the
equals
(“=”).

4. Type
a
comma
(“,”),
your
variable
name,
and
a
close
parenthesis
(“)”).

5. Press
[ENTER].

The
calculator
will
show
BUSY
in
the
lower‐right
corner
and
then
print
the
solution.


Solving
in
MATLAB

The
core
MATLAB
program
doesn’t
explicitly
include
a
solver,
but
most
versions

(including
the
academic
student
version)
ship
with
two
toolboxes
containing

solvers:
the
Symbolic
Math
Toolbox
and
the
Optimization
Toolbox.
MATLAB
code
is

attached
to
evaluate
the
solution
to
Theme
Problem
3
by
each
method;
below
I

describe
some
guidelines.

(Note:
as
a
rule,
fsolve
is
easier
to
use
and
faster.
solve
demands
a
more

specifically‐formed
input,
runs
more
slowly,
and
gives
multiple
solutions,
of
which

only
one
is
correct.)

Optimization
Toolbox

In
this
toolbox
is
the
command
fsolve(fun,x0).
This
program
calls
on
another

function
–
fun
–
into
which
it
will
enter
guesses
starting
with
x0
until
fun
returns
0.

This
function
can
be
entered
in
a
separate
file,
but
it
is
better
to
use
what
is
called
an

anonymous
function
handle.
This
creates
a
variable
inside
your
m‐file
(or
just
in
the

workspace,
if
you
type
it
at
the
command
line)
to
act
as
a
function.
It
cannot
be
very

sophisticated,
but
it
doesn’t
need
to
be.
Proceed
as
follows.

1. Choose
your
variable‐name
for
the
function
–
fun
will
do
as
an
example,
you

may
use
any
variable
name
–
and
one
for
the
variable
to
be
solved
–
x
will
do;

again,
you
can
use
any.

2. Type
on
one
line
–
without
pressing
Enter
–
“fun = @(x)
”

3. …and
continue
the
line
with
the
equation
you
are
solving,
as
if
your
unknown

–
x
here
–
is
known.
Write
it
so
that
fun(x)
=
0
corresponds
to
the
solution.

4. Choose
an
initial
guess
for
the
solution.
(When
solving
for
temperatures,
I

like
to
choose
a
temperature
like
that
in
the
problem
–
Tair,
for
example.)

5. Evaluate
fsolve
with
the
name
of
your
function
as
the
first
input
and
your

initial
guess
as
the
second.

This
will
give
you
a
single
number
as
the
output,
which
should
be
a
solution
to
the

equation.
If
it
is
not,
or
if
it
is
an
unphysical
solution,
try
a
different
initial
guess.

ENME332
–
2010.02.02
 
 3



Symbolic
Math
Toolbox

In
this
toolbox
is
the
command
solve(eq,var).
For
our
purposes,
the
easiest

thing
to
do
is
write
out
the
equation
as
a
string;
the
least
confusing
way
to
do
this
is

to
do
the
algebra
yourself.

1. Write
out
the
equation
on
paper
in
terms
of
your
unknown
with
decimal

coefficients
and
constants.
See
the
attached
code
for
an
example.

2. Type
this
equation
in
with
the
variable
name
of
your
choice
for
the
unknown

(single
letters
such
as
“T”
are
safest)
and
all
decimal
values,
as
a
string.
Save

it
as
a
variable
with
an
obvious
name
(for
example,
“equation”).

3. Run
the
solve
command,
calling
your
equation
and
a
string
corresponding
to

your
variable
name.
For
example,
solve(equation,T).

This
final
step
will
output
a
column
of
possible
solutions
to
your
equation.
Use
your

engineering
judgment
to
pick
the
correct
answer.


1b.
Automatic
Graphing

If
you
enter
the
right‐
and
left‐hand
sides
of
the
desired
equality
as
functions
in
your

unknown
variable,
you
may
plot
them
over
the
desired
range
and
look
for
the

intersection.
Sometimes
there
will
be
an
automatic
program
to
find
this

intersection;
otherwise
you
may
zoom
into
the
plot
until
you
have
the
desired

precision
on
the
axes.
(Remember
to
calculate
enough
points
to
get
a
good
figure
if

you
use
MATLAB.)


2.
Textbook
Root‐Finding
Algorithms

There
are
in
the
world
vast
numbers
of
textbook
numerical
methods
for
finding

roots
(points
at
which
an
equation
equals
zero).
Some
well‐known
simple
ones
are:

• The
bisection
method

o Advantages:
Straightforward,
robust.

o Disadvantages:
Very
slow.

• Newton's
method

o Advantages:
Very
fast.

o Disadvantages:
Requires
differentiation,
may
fail
to
converge
or

converge
to
incorrect
root.

• The
secant
method

o Advantages:
Fast.

o Disadvantages:
May
fail
to
converge
or
converge
to
incorrect
root.

• The
regula
falsi
(false
position)
method

o Advantages:
Robust.

o Disadvantages:
Irregular
convergence
speed
(up
to
as
fast
as
the

secant
method,
down
to
slower
than
bisection).

These
methods
and
many
others
are
described
in
detail
in
many
books
and
on
many

websites;
I
present
only
summaries
here.

ENME332
–
2010.02.02
 
 4



Bisection
Method

This
method
works
by
successively
dividing
the
possible
space
of
solutions
in
half

until
the
answer
falls
out.

1. Write
problem
in
the
form
f(x)
=
0,
where
x
is
the
variable
to
be
solved
for.

2. Find
two
points
a0
and
b0
near
the
root
such
that
f(a0)
and
f(b0)
are
of

opposite
sign.
Say
that
f(a0)
is
positive
and
f(b0)
is
negative.

3. Calculate

a +b
c0 = 0 0 

2
and
f(c0).

4. If
f(c0)
is
negative,
set
a1
=
a0
and
b1
=
c0.
If
f(c0)
is
positive,
set
a1
=
c0
and
b1
=

b0.
This
will
leave
you
with
two
points
like
those
you
began
with,
save
that

€ the
interval
containing
the
root
is
half
as
long.

5. Repeat
3
and
4
until
your
interval
(i.e.
error)
is
small
enough
for
your

satisfaction
(e.g.
 a − b < c /2000 
for
three
significant
figures).
Note
that
you

can
always
predict
how
long
this
will
take.

When
to
avoid
this
method:
When
any
other
method
works.


Newton's
Method

Also
known
as
the
Newton‐Raphson
or
Newton‐Fourier
method,
this
works
by

calculating
where
the
root
should
be
from
the
slope
at
the
current
guess.

1. Write
problem
in
the
form
f(x)
=
0,
where
x
is
the
variable
to
be
solved
for.

2. Calculate
the
derivative
function
f'(x).

3. Find
a
point
a0
near
the
root.

4. Calculate
f(a0)
and
f'(a0).

5. Calculate

a1 = a0 − f ( a0 ) f ′( a0 ) 

(i.e.
the
x‐intercept
of
a
tangent
line
at
a0.)

6. Repeat
4
and
5
until
the
corrections
between
repetitions
is
small
enough
for

your
satisfaction
(e.g.
 f ( an ) f ′( an ) < an /2000 
for
three
significant
figures).


When
to
avoid
this
method:
When
the
function
has
large
derivatives
and
a
good

initial
guess
is
not
available;
when
the
function
derivative
is
difficult
to
obtain.


Secant
Method

An
approximation
of
Newton’s
method,
this
takes
two
guesses
and
their

corresponding
function
values
and
draws
a
line
between
them
to
find
a
third.
This

third
point
replaces
the
older
of
the
previous
two.

1. Write
the
problem
in
the
form
f(x)
=
0,
where
x
is
the
variable
to
be
solved

for.

2. Find
two
distinct
points
a0
and
a1
near
the
root.

3. Calculate
f(a0)
and
f(a1).

ENME332
–
2010.02.02
 
 5



4. Calculate

a1 − a0
a2 = a1 − f ( a1 )
f ( a1 ) − f ( a0 )

f ( a1 ) a0 − f ( a0 ) a1
=
f ( a1 ) − f ( a0 )
(i.e.
the
x‐intercept
of
the
line
connecting
a0
and
a1
–
notice
that
the
second

term
in
the
first
line
is
a
discrete
approximation
of
 f ( a0 ) f ′( a0 ) ).

5. Repeat
3
and
4
with
the
two
latest
a‐values
(a1
and
a2,
a2
and
a3,
…)
until
the


corrections
between
repetitions
is
small
enough
for
your
satisfaction.

When
to
avoid
this
method:
When
the
function
has
large
derivatives
and
a
good


initial
pair
of
guesses
is
not
available;
when
Newton's
method
is
available.

Regula
Falsi
(False
Position)
Method

This
combines
the
ideas
of
the
bisection
method
and
secant
method:
you
bracket
the

solution
and
then
continue
finding
points
closer
and
closer
to
the
root
by
drawing

lines
between
your
two
points.

1. Write
the
problem
in
the
form
f(x)
=
0,
where
x
is
the
variable
to
be
solved

for.

2. Find
two
points
a0
and
b0
near
the
root
such
that
f(a0)
and
f(b0)
are
of

opposite
sign.
Say
that
f(a0)
is
positive
and
f(b0)
is
negative.

3. Calculate

f ( a0 )b0 − f (b0 ) a0
c0 = 

f ( a0 ) − f (b0 )
(the
secant‐method
formula).

4. If
f(c0)
is
negative,
set
a1
=
a0
and
b1
=
c0.
If
f(c0)
is
positive,
set
a1
=
c0
and
b1
=

b0
(the
bisection
method
procedure).
This
will
give
you
two
points
like
those

€ you
began
with,
save
that
the
interval
containing
the
root
is
shorter.


5. Repeat
3
and
4
with
the
latest
pair
of
a,
b
values
until
a
or
b
approximates
the

solution
to
your
satisfaction.

Note:
 Sometimes
one
point
converges
slowly
to
the
solution
while
the
other

remains
unchanged
for
many
repetitions.
One
way
to
fix
this
is
to
alter
the

formula
whenever
the
same
endpoint
is
retained
twice
in
a
row
to

w ⋅ f ( a)b − f (b) a f ( a)b − w ⋅ f (b) a
c= 
or
 c = 

w ⋅ f ( a) − f (b) f ( a) − w ⋅ f (b)
where
0
<
w
<
1
is
a
factor
on
the
value
at
the
point
that
was
retained
twice.

This
will
force
the
point
in
question
to
be
replaced
for
the
next
iteration
if
w

is
sufficiently
small.

€ €
When
to
avoid
this
method:
When
Newton's
method
or
the
secant
method
is
reliable.

Convergence
Speeds
of
Methods

In
each
case,
the
initial
guess
was
taken
as
200
K,
400
K,
or
the
range
{200
K,
400
K}.

ENME332
–
2010.02.02
 
 6



• Bisection
Method:
19
halvings
to
attain
six
correct
significant
figures.

• Newton’s
Method:
3
iterations
to
attain
six
correct
significant
figures.

• Secant
Method:
5‐6
iterations
to
attain
six
correct
significant
figures.

• Regula
Falsi:
5‐6
iterations
to
attain
six
correct
significant
figures.

As
can
be
seen,
Newton’s
method
is
the
fastest
of
these.


Final
Note
on
Textbook
Methods

These
methods
are
included
for
completeness
only
–
there
are
much
better
methods

known,
and
these
better
methods
are
likely
to
have
already
been
programmed
into

your
calculator
or
computer.
Even
if
they
are
not,
it
is
still
often
worth
checking
a

problem‐specific
method
(below)
before
resorting
to
one
of
these.


3.
Iterated
Thermal
Resistance

Given
that
the
problems
we
are
solving
are
heat
transfer
problems,
it
seems
likely

that
some
scheme
could
take
specific
advantage
of
this
fact.
One
way
in
which
you

may
do
so
is
by
the
idea
of
thermal
resistance.
The
logic
is
simple:
if
the
thermal

resistance
depends
on
temperature,
but
does
not
change
much
as
the
temperature

ranges
from
your
initial
guess
to
the
correct
solution,
then
you
should
be
able
to
use

the
resistance
from
your
guess
to
determine
the
solution.

In
our
course,
there
are
two
obvious
cases
where
we
may
need
to
solve
for
a

thermal
resistance
that
depends
on
the
temperature:
convection
and
radiation.
(The

variation
of
k
with
temperature
is
usually
so
weak
as
to
be
negligible
during
this

course.)
In
both
cases,
the
resistance
may
be
calculated
from
the
heat
transfer

coefficient:

1
R= 

hA
…and,
when
we
come
to
study
convection,
equations
for
h
will
be
supplied.
In
the

present
instance,
the
equation
for
hr
–
the
equivalent
heat
transfer
coefficient
for

radiation
–
is
needed;
it
may
be
calculated
from
our
rate
equation
as
follows:


q = Aεσ (Tsurf
4 4
− Tsurr )
= Ahr (Tsurf − Tsurr );
4 4
Tsurf − Tsurr
hr = εσ
Tsurf − Tsurr
(T 2
surf
2
+ Tsurr )(Tsurf2 − Tsurr
2
) 

= εσ
Tsurf − Tsurr

= εσ
(T 2
surf
2
+ Tsurr )(Tsurf + Tsurr )(Tsurf − Tsurr )
Tsurf − Tsurr
= εσ (Tsurf
2 2
+ Tsurr )(Tsurf + Tsurr )


ENME332
–
2010.02.02
 
 7



In
the
case
where
Tsurf
≈
Tsurr,
this
may
be
reduced
to

hr = 4εσT 3 

…but
that
does
not
always
hold;
it
is
best
considered
an
approximation
only.

In
any
case,
once
the
formulae
for
the
resistances
is
found,
you
can
draw
a


resistance
network
and
write
algebraically
the
solution
in
terms
of
h
and/or
h r.

Using
the
example
of
Theme
Problem
3
for
Exam
1:

qheater = hA(T − Tair ) + hr A(T − Tsky ) 


…and
this
may
be
rearranged
to

qheater + hATair + hr ATsky
€ T= 

( h + hr ) A
The
solution
at
this
point
is
straightforward:
guess
a
value
of
T,
substitute
this
value

into
the
equation
for
hr
(in
this
case),
and
then
use
this
value
of
hr
to
calculate
a
new

value
of
T.
This
may
be
repeated
until
the
value
of
T
satisfies
the
original
equation
to


the
desired
precision.

(In
Theme
Problem
3
for
Exam
1,
this
converges
quickly:
starting
at
200
K
or
400
K,

the
calculations
of
hr
and
T
by
the
above
equations
converges
in
five
iterations
to
six

significant
figures.)


4.
Trial
and
Error

Unlike
the
other
methods,
there
is
no
formula
to
follow
here.
Also
unlike
the
other

methods,
however,
this
will
give
you
the
answer
as
reliably
as
you
can
calculate
it:

by
guessing
and
observing
the
size
and
direction
of
your
error,
you
will
quickly

learn
the
range
in
which
the
answer
lies
and
eventually
narrow
down
on
the
precise

number.
Some
tips:

• The
correct
answer
will
be
reasonable;
if
you
cannot
find
a
reasonable

answer,
check
your
equations.

• Almost
always
in
this
class,
the
error
in
your
equation
will
change
sign
when

you
go
from
a
too‐low
temperature
to
a
too‐high
temperature
(or
vice‐versa).

This
will
give
you
a
range.

• Pay
attention
to
how
quickly
your
error
changes
as
you
change
your
answer;

this
will
give
you
a
clue
how
close
you
are
and
how
much
to
jump.

Good
luck!


Please
direct
comments
and
corrections
to
Robin
Zimmermann
–
robin.zimm@gmail.com

ENME332
–
2010.02.02
 
 8



Appendix
I:
MATLAB
Example
Code

The
code
I
used
is
as
follows:

% MATLAB solution of nonlinear equations
% Based on Theme Problem 3, Exam 1.
% Equation:
% q_heater = h*A*(T_windshield-T_air) +
% epsilon*sigma*A*(T_windshield^4-T_sky^4)
% equivalently:
% 70 = 20*1*(T-278.15) + 0.4*5.67e-8*(T^4-4^4)
clear all

% Problem Parameters
q_heater = 70;
A = 1;
h = 20; T_air_C = 5;
T_air = T_air_C + 273.15; % in Kelvin
epsilon = 0.4; sigma = 5.67e-8; T_sky = 4;

%% Symbolic Toolbox Method


% To use "solve" in the symbolic toolbox, the equation must be in its
% simplified form:
% 2.268e-8 * T^4
% + 20 * T
% - 5563.0000058061 [the sum of the two constants]
% = 70
% so we shall proceed as follows.

% In these lines, we have calculated the numbers out by hand and typed them
% in directly:
T_eqn_1 = '2.268e-8*T^4+20*T-5563.0000058061=70';
T_symbolic_1 = solve(T_eqn_1, 'T')

% In these lines, we write the expression with our variables:


T_eqn_2 = 'epsilon*sigma*A*T^4+h*A*T-epsilon*sigma*T_sky-h*A*T_air=q_heater';
T_symbolic_2_a = solve(T_eqn_2, 'T')
% and then plug in the numbers:
T_symbolic_2_b = subs(T_symbolic_2_a)

% Better in general is the operation in these lines: first substitute:


T_eqn_3_a = 'epsilon*sigma*A*T^4+h*A*T-epsilon*sigma*T_sky-h*A*T_air=q_heater';
T_eqn_3_b = subs(T_eqn_3_a)
% ...and then solve:
T_symbolic_3 = solve(T_eqn_3_b, 'T')

%% Optimization Toolbox Method


% To use "fsolve" in the optimization toolbox, you have to have a
% function which will output 0 when the solution is correct. In this
% case, that means
% f(x) = h*A*(T_windshield-T_air) +
% epsilon*sigma*A*(T_windshield^4-T_sky^4) - q_heater
% so we shall proceed as follows.

% First, we define our function using an anonymous function


% handle:
balance = @(T) h*A*(T-T_air) + epsilon*sigma*A*(T^4-T_sky^4) - q_heater
% ...and then plug this into the fsolve with a reasonable initial guess -
% I choose T_air, as the surface is in heat transfer with the air:
T_optimization = fsolve(balance, T_air)

%% Plotting Method

T_min = 200; T_max = 400; % feel free to choose an appropriate range based
% on your judgment; you may modify it if you find it unsatisfactory.

nT = 10000; % generous.

T_plot = linspace(T_min, T_max, nT);

% The solution will be done by plotting the left- and right-hand sides of
% the equation and looking for an intersection; for efficiency, these
ENME332
–
2010.02.02
 
 9



% arrays should be preallocated by being filled with zeros.


LHS_plot = zeros(1, nT); RHS_plot = zeros(1, nT);
for i = 1:nT
% From the equation given:
LHS_plot(i) = q_heater;
RHS_plot(i) = h*A*(T_plot(i)-T_air) + ...
epsilon*sigma*A*(T_plot(i)^4-T_sky^4);
% Note that T_plot(i) is used for T_windshield.
end

plot(T_plot, LHS_plot, 'k:', ... % This makes a dotted black line.


T_plot, RHS_plot, 'k-'); % This makes a solid black line.


Please
note
that
the
output
to
this
code
is
not
formatted
for
easy
reading;
at
several

points
intermediate
results
are
printed
that
are
cumbersome
in
length
for

illustrative
purposes.
ENME332
–
2010.02.02
 
 10



Appendix
II:
Theme: ice deposit on the car windows, solving one nonlinear


algebraic equation
Given:
a
heater
that
generates
70W
is
placed

inside
the
car.
The
outer
surface
of
the
window
 Tsky

has
emissivity
=
0.4,
h
=
20
W/m2‐K,
T∞
=
5
°C.
The

car
window
is
facing
the
clear
sky
(4K).
The
area

is
1
m2.

Find
Twindow.

Tair,
h


q


Das könnte Ihnen auch gefallen