Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Second-order Boundary Value Problems

bvp - Shooting method


The shooting method is based on converting the boundary-value problem into an equivalent initial-value
problem by determining the missing initial values that are consistent with the boundary values.

A trial-and-error approach is implemented to develop a solution for the initial-value version that satisfies the
given boundary conditions.

Ecuación diferencial lineal de segundo orden


Because the two conditions are given at different values of the independent variable, this is called a two-point
boundary value problem.

y''- 4*y=0

y(0)=1, y(1)=3 Dirichlet boundary condition

A sequence of IVPs is produced, converging to the correct one. The sequence begins with an initial guess for
the slope s=y'(a), provided to go along with the initial value y(a). The IVP that results from this initial slope
is solved and compared with the boundary value yb. By trial and error, the initial slope is improved until the
boundary value is matched. The boundary value problem is reduced to solving the equation

ShootingF(s) = 0

to find the slope s=y'(a)

% y'' = 4*y
% y' = z
% z' = 4*y
% y(0)=1, y'(0)=¿?, y(1)=3
M = [0,1;4,0];
yzdot = @(t,yz) M*yz;
a=0;
b=1;
ya=1;
yb=3;
N=100; % número de puntos (índices:1 a N; N-1 pasos)
h=(b-a)/(N-1);
% [ya;s] es la condicion inicial
% y el target es la componente 1 de yz y(1)=yb
target = 1;
g = @(s) Shooting(yzdot, h, a, b, ya, s, target) - yb;
% Find starting values that bracket the root s; residual <0 y >0
r = g(-1);

1
Unrecognized function or variable 'Shooting'.

Error in EjerciciosBVP (line 16)


g = @(s) Shooting(yzdot, h, a, b, ya, s, target) - yb;

r = g(0);
% Find the root s
[ydota,~] = bisect(g,-1,0); % valor de s=y'(a) (=-0.4203)

Finally, the solution can be traced (by an IVP solver) as the solution to the initial value problem

yz0 = [ya; ydota]; % punto inicial (índice 1)

solver = 'rk4';
[t,yz] = ivpsV(yzdot, yz0, a, b, h, solver);
plot(t,yz(1,:));
xlabel('t');
ylabel('y');
grid on;

El balance de calor de estado estacionario de una barra se representa como

Obtenga la solución T(x) para una barra de 10m con T(0)=240 y T(10)=150

Resuelva con las condiciones de frontera y(0) =5 y y(20)=8

Sistema de ecuaciones diferenciales de primer orden


For systems of ordinary differential equations, boundary value problems arise in many forms (boundary
conditions).

bvp - Finite Difference method

2
Replace the derivatives with the discrete versions and solve the resulting, simpler, algebraic equations.

Ecuación diferencial lineal de segundo orden

Use the centered difference form of the second derivative accurate up to an error proportional to .

y''-4*y=0

y''(i) - 4y(i) = (y(i-1)-2y(i)+y(i+1))/h^2 - 4y(i) = 0

y(i-1)-2y(i)+y(i+1)-4*h^2*y(i) = 0

y(i-1)-(2+4*h^2)*y(i)+y(i+1)) = 0

y considerando y(1)=1 y y(N)=3 (boundary conditions)

1 - (2+4*h^2)*y(2) + y(3) =0

y(2) - (2+4*h^2)*y(3) + y(4) = 0

y(3) - (2+4*h^2)*y(4) + y(5) = 0

...

y(N-2) - (2+4*h^2)*y(N-1)+3 = 0

finalmente (tenemos una matriz tridiagonal con N-2 variables: 2 a N-1)

-(2+4*h^2)*y(2) + y(3) = -1

y(2) - (2+4*h^2)*y(3) + y(4) = 0

y(3) - (2+4*h^2)*y(4) + y(5) = 0

...

y(N-2) - (2+4*h^2)*y(N-1) = -3

Since the nodes are numbered consecutively, and since each equation consists of a node (i) and its adjoining
neighbors (i-1 and i+1), the resulting set of linear algebraic equations will be tridiagonal. As such, they can be
solved with the efficient algorithms that are available for such systems. Further, inspection of the coefficients
on the left-hand side indicates that the system of linear equations will also be diagonally dominant. Hence,
convergent solutions can also be generated with iterative techniques like the Gauss-Seidel method.

a=0;
b=1;
ya=1;
yb=3;
N=100;

3
h=(b-a)/(N-1);

% w(i) = y(i+1) matriz de puntos interiores


bv=zeros(N-2,1);
bv(1) = -ya;
bv(N-2) = -yb;
diagonal = -(2+4*h^2)*ones(N-2,1);
subdiagonal = ones(length(diagonal),1);
superdiagonal = subdiagonal;
w = GaussTridiag(subdiagonal,diagonal,superdiagonal,bv);

y=zeros(N,1);
y(1) = ya;
y(N) = yb;
y(2:N-1) = w;

t=a:h:b;
plot(t,y);
title('Método de diferencias finitas');
xlabel('t');
ylabel('y');
grid on;

4
El balance de calor de estado estacionario de una barra se representa como

Obtenga la solución T(x) para una barra de 10m con T(0)=240 y T(10)=150

Usando el método de diferencias finitas, resuelve el siguiente problema:

g0 = @(t) -t/7;
g1 = @(t) 1/7 + 0*t;
g2 = @(t) 2/7 + 0*t;
tspan = [0,20];
bc = [5,8];
n = 100;
[t,y] = bvp2ode(g0,g1,g2,tspan,bc,n);

u = 1×100
-0.0283 -0.0566 -0.0849 -0.1132 -0.1414 -0.1697 -0.1980 -0.2263
v = 1×100
0.1429 0.1429 0.1429 0.1429 0.1429 0.1429 0.1429 0.1429

plot(t,y);

5
[t,y] = bvp2ode2(g0,g1,g2,tspan,bc,n);
plot(t,y)

6
Function bvp2ode

Write the function bvp2ode that computes the numerical solution of the boundary value problem

function [t, y] = bvp2ode(g0, g1, g2, tspan, bc, n)

where

g0, g1, and g2 are function handlers.

t0 and tf are stored in the vector tspan =[t0 tf]

y0 and yf are stored in the vector bc = [y0 yf].

n is the number of interior points (there are n+2 points counting the borders)

y is a column vector.

7
Use standard second order approximations for y' and y'' to construct a linear system of

equations for computing approximate values of the function y on the set of evenly spaced points.

Central finite differences:

function [t, y] = bvp2ode(g0, g1, g2, tspan, bc, n)


a = tspan(1);
b = tspan(2);
t = linspace(a, b, n+2);
t1 = t(2:n+1);
u = g0(t1)
v = g1(t1)
w = g2(t1);
h = (b-a)/(n+1);

d1 = 1 + h*w(1:n-1)/2;
d2 = -(2 + v(1:n)*h^2);
d3 = 1 - h*w(2:n)/2;
A = diag(d1, -1) + diag(d2) + diag(d3, 1);
f = zeros(n, 1);
f(1) = h^2*u(1) - (1 + h*w(1)/2)*bc(1);
f(n) = h^2*u(n) - (1 - h*w(n)/2)*bc(2);
f(2:n-1) = h^2*u(2:n-1)';
s = A\f;
y = [bc(1);s;bc(2)];
t = t';
end

function [t, y] = bvp2ode2(g0, g1, g2, tspan, bc, n)


a = tspan(1);
b = tspan(2);
t = linspace(a, b, n+2);
t1 = t(2:n+1);
u = g0(t1);
v = g1(t1);
w = g2(t1);
h = (b-a)/(n+1);

subdiagonal = 1 + h*w(1:n-1)/2;
subdiagonal = [0,subdiagonal];
diagonal = -(2 + v(1:n)*h^2);
superdiagonal = 1 - h*w(2:n)/2;
superdiagonal = [superdiagonal,0];
f = zeros(n, 1);

8
f(1) = h^2*u(1) - (1 + h*w(1)/2)*bc(1);
f(n) = h^2*u(n) - (1 - h*w(n)/2)*bc(2);
f(2:n-1) = h^2*u(2:n-1)';
w = GaussTridiag(subdiagonal,diagonal,superdiagonal,f);
y = [bc(1);w';bc(2)];
t = t';
end
function x=tridiagonal(e,f,g,r)
n=length(f);

for i=2:n;
mult= e(i)/f(i-1);
f(i)=f(i)-mult*g(i-1);
r(i)=r(i)-mult*r(i-1);
end

%sustitución hacia atrás simplificada


x=zeros(n,1);
x(n)=r(n)/f(n);
for i=n-1:-1:1;
x(i)=(r(i)-g(i)*x(i+1))/f(i);
end

end

You might also like