0% found this document useful (0 votes)
74 views49 pages

BVP 1

The document discusses solving boundary value problems using finite difference techniques. It presents an example of using finite differences to solve the boundary value problem for the temperature distribution in cooling fins on a computer chip. The finite difference approach transforms the differential equation into a system of equations that can be solved numerically. It also demonstrates solving the boundary value problem using Matlab's built-in bvp4c routine, which automates the finite difference method. Special considerations for boundary conditions involving derivatives are also addressed.

Uploaded by

Helios5993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views49 pages

BVP 1

The document discusses solving boundary value problems using finite difference techniques. It presents an example of using finite differences to solve the boundary value problem for the temperature distribution in cooling fins on a computer chip. The finite difference approach transforms the differential equation into a system of equations that can be solved numerically. It also demonstrates solving the boundary value problem using Matlab's built-in bvp4c routine, which automates the finite difference method. Special considerations for boundary conditions involving derivatives are also addressed.

Uploaded by

Helios5993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Boundary Value Problems

Jake Blanchard
University of Wisconsin - Madison
Spring 2008

Case Study
We will analyze a cooling configuration for a
computer chip
We increase cooling by adding a number of
fins to the surface
These are high conductivity (aluminum) pins
which provide added surface area

The Case - Schematic

The Case - Modeling

The temperature distribution in the pin is


governed by:
2

d T hC

(
T

T
)

0
f
2
dx
kA
T (0) 40 C
dT
x L 0
dx

Finite Difference Techniques


Used to solve boundary value problems
Well look at an example

d y

1
2
dx

y ( 0) 1

y( ) 0
2

Two Steps
Divide interval into steps
Write differential equation in terms
of values at these discrete points

Solution is Desired from x=0 to /2

X=0

X= /2

Divide Interval into Pieces

X0=0

X1

X2

X3

X4= /2

Boundary Values
y(0)=1
y(/2 )=0
X0=0

X1

X2

X3

X4= /2

Calculate Internal Values


y2
y0

y1

y3
y4

X0

X1

X2

X3

X4

Approximations
y2

y1

y2-y1
h

dy
dx

i 1/ 2

yi 1 yi

Second Derivative

yi 1 2 yi yi 1
d y

i
2
2
dx
h
2

Substitute
2

d y
y 1
2
dx
becomes
yi 1 2 yi yi 1
yi 1
2
h
or
yi 1 (2 h ) yi yi 1 h
2

Equations

Boundary Conditions

Equations

y2 2 y1 y0 h 2 y1 h 2

Boundary Conditions

Equations

Boundary Conditions

y2 2 y1 y0 h 2 y1 h 2

y3 2 y2 y1 h 2 y2 h 2

Equations

y2 2 y1 y0 h 2 y1 h 2

Boundary Conditions

y4 2 y3 y2 h 2 y3 h 2

y3 2 y2 y1 h 2 y2 h 2

Using Matlab
y0 1
y0 (2 h ) y1 y2 h

y1 (2 h ) y2 y3 h

y 2 ( 2 h ) y3 y 4 h
2

y4 0
Convert to matrix and solve

Using Matlab
0
0
0
1
1 (2 h 2 )
1
0

2
0
1
(2 h )
1

2
0
0
1

(
2

h
)

0
0
0
0

0 y0 1

2
0 y1 h
2
0 y 2 h
2
1 y3
h

1 y4 0

The Script
h=pi/2/4;
A=[1 0 0 0 0; 1 -(2-h^2) 1 0 0; 0 1 -(2-h^2) 1 0;
...
0 0 1 -(2-h^2) 1; 0 0 0 0 1];
b=[1; h^2; h^2; h^2; 0];
x=linspace(0,pi/2,5);
y=A\b;
plot(x,y)

What if we use N divisions


N divisions, N+1 mesh points
Matrix is N+1 by N+1

2
h
N

The Script

N=4;
h=pi/2/N;
A=-(2-h^2)*eye(N+1);
A(1,1)=1;
A(N+1,N+1)=1;
for i=1:N-1
A(i+1,i)=1;
A(i+1,i+2)=1;
end
b=h^2*ones(N+1,1);
b(1)=1;
b(N+1)=0;
x=linspace(0,pi/2,N+1);
y=A\b;
plot(x,y)

Results
1
0.9
0.8
0.7
1
0.6

0.8

0.4

0.7

0.3

0.6

0.2
y

0.9
0.5

0.5

0.1
0.4
0

0.2

0.4

0.6

0.8
x

1.2

1.4

1.6

0.3
0.2
0.1

N=4

0.2

0.4

0.6

0.8
x

N=20

1.2

1.4

1.6

Script Using Diag


The diag command allows us to put a
vector on the diagonal of a matrix
We can use this to put in the 1s just off
the diagonal in this matrix
Syntax: diag(V,K) - V is the vector, K tells
which diagonal to place the vector in

New Script
A=-(2-h^2)*eye(N+1)+diag(v,1)+diag(v,-1);
A(1,2)=0;
A(N+1,N)=0;
A(1,1)=1;
A(N+1,N+1)=1;

A Built-In Routine
Matlab includes bvp4c
This carries out finite differences on systems of
ODEs
SOL =
BVP4C(ODEFUN,BCFUN,SOLINIT)

odefun defines ODEs


bcfun defines boundary conditions
solinit gives mesh (location of points) and guess for
solutions (guesses are constant over mesh)

Using bvp4c
odefun is a function, much like what we
used for ode45
bcfun is a function that provides the
boundary conditions at both ends
solinit created in a call to the bvpinit
function and is a vector of guesses for the
initial values of the dependent variable

Preparing our Equation


Let y be variable 1 y(1)
Then dy/dx (=z) is variable 2 y(2)

d2y
y 1
2
dx
dy
z y ( 2)
dx
d 2 y dz

1 y (1)
2
dx
dx

y ( 0) 1

y( ) 0
2

function dydx = bvp4ode(x,y)


dydx = [ y(2) 1-y(1) ];

Boundary Conditions
ya(1) is y(1) at x=a
ya(2) is y(2) at x=a
yb(1) is y(1) at x=b
yb(2) is y(2) at x=b
In our case, y(1)-1=0 at x=a and
y(1)=0 at x=b

function res = bvp4bc(ya,yb)


res = [ ya(1)-1 yb(1) ];

Initialization
How many mesh points? 10
Initial guesses for y(1) and y(2)
Guess y=1, z=-1
Guess more critical for nonlinear equations
xlow=0;
xhigh=pi/2;
solinit =
bvpinit(linspace(xlow,xhigh,10),[1 -1]);

Postprocessing
xint = linspace(xlow,xhigh);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))

The Script
function bvp4
xlow=0; xhigh=pi/2;
solinit = bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint = linspace(xlow,xhigh);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
% ----------------------------------------------function dydx = bvp4ode(x,y)
dydx = [ y(2)
1-y(1) ];
% ----------------------------------------------function res = bvp4bc(ya,yb)
res = [ ya(1)-1
yb(1) ];

Things to Change for Different


Problems
function bvp4
xlow=0; xhigh=pi/2;
solinit = bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint = linspace(xlow,xhigh,20);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
% ----------------------------------------------function dydx = bvp4ode(x,y)
dydx = [ y(2)
1-y(1) ];
% ----------------------------------------------function res = bvp4bc(ya,yb)
res = [ ya(1)-1
yb(1) ];

Practice
Download the file
bvpskeleton.m and
modify it to
solve the boundary
value problem shown
at the right for =0.1
and compare to the
analytical solution.

d y dy
2 0
dx
dx
y ( 0) 0
y (1) 1
yanalytical

e
e

1
1

bvpskeleton.m
xlow=???;
xhigh=???;
solinit = bvpinit(linspace(xlow,xhigh,20),[1 0]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint = linspace(xlow,xhigh);
Sxint = deval(sol,xint);
eps=0.1;
analyt=(exp(xint/eps)-1)/(exp(1/eps)-1);
plot(xint,Sxint(1,:),xint,analyt,'r')
% ----------------------------------------------function dydx = bvp4ode(x,y)
eps=0.1;
dydx = [ ???? ; ???? ];
% ----------------------------------------------function res = bvp4bc(ya,yb)
res = [ ???? ; ???? ];

What about BCs involving


derivatives?
If we prescribe a derivative at one end, we
cannot just place a value in a cell.
Well use finite difference techniques to
generate a formula
The formulas work best when centered,
so we will use a different approximation
for the first derivative.

Derivative BCs
Consider a boundary condition of the
form dy/dx=0 at x=L
Finite difference (centered) is:

dy yi 1 yi 1

0
dx
2h
or
yi 1 yi 1

Derivative BCs
So at a boundary point on the right we
just replace yi+1 with yi-1 in the formula
Consider:

d y

0
2
dx

y ( 0) 1
dy
(1) 0
dx

Finite Difference Equation

We derive a new difference equation


d2y
y0
2
dx
becomes
yi 1 2 yi yi 1
yi 0
2
h
or
yi 1 (2 h 2 ) yi yi 1 0

Derivative BCs

The difference equation at the last point


is

y N 1 2 h y N y N 1 0
2

but
y N 1 y N 1
so

2 y N 1 2 h 2 y N 0

Final Matrix
0
0
0
0
1
y0 1
1 (2 h 2 )
y 0
1
0
0

1
2
0
y2 0
1
(2 h )
1
0


2
0
1
(2 h )
1
0
y3 0
0
0
0
2
(2 h 2 ) y4 0

New Code
h=1/4
A=[1 0 0 0 0;
1 -(2-h^2) 1 0 0;
0 1 -(2-h^2) 1 0;
0 0 1 -(2-h^2) 1;
0 0 0 2 -(2-h^2)]
B=[1; 0; 0; 0; 0]
y=A\B

Using bvp4c

The boundary condition routine allows us


to set the derivative of the dependent
variable at the boundary

Preparing Equation
2

d y
y0
2
dx
dy
z y ( 2)
dx
2
d y dz

y (1)
2
dx
dx

y ( 0) 1
dy
(1) 0
dx
so
ya (1) 1
yb ( 2) 0
or
ya (1) 1 0
yb ( 2) 0

The Script

function bvp5
xlow=0; xhigh=1;
solinit = bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol = bvp4c(@bvp5ode,@bvp5bc,solinit);
xint = linspace(xlow,xhigh);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
% ----------------------------------------------function dydx = bvp5ode(x,y)
dydx = [ y(2)
-y(1) ];
% ----------------------------------------------function res = bvp5bc(ya,yb)
res = [ ya(1)-1
yb(2) ];

Practice
Solve the Case
Study Problem
Use L=25 mm,
Tf=20 C, and
hC/kA=4000 /m2
JPB: need a
skeleton here

d T hC

(T T f ) 0
2
dx
kA
T (0) 40 C
dT
x L 0
dx

Practice
A 1 W, 2 Mohm resistor
which is 30 mm long
has a radius of 1 mm.
Determine the peak
temperature if the
outside surface is held
at room temperature.
Use k=0.1 W/m-K and
Q=2.1 MW/m2

d 2T 1 dT Q

0
2
dr
r dr k
T ( R ) 20 C
dT
( 0) 0
dr

Practice
Repeat the previous
2
d T 1 dT Q

0
problem with
2
dr
r dr k
convection to external
1
environment.
hT ( R ) Te QR
2
Use k=0.1 W/m-K and
dT
2
Q=2.1 MW/m
( 0) 0
dr
2
Also,h=10 W/m -K and
Te=20 C

Questions?

You might also like