Professional Documents
Culture Documents
Ejercicios BVP
Ejercicios BVP
A trial-and-error approach is implemented to develop a solution for the initial-value version that satisfies the
given boundary conditions.
y''- 4*y=0
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
% 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'.
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
solver = 'rk4';
[t,yz] = ivpsV(yzdot, yz0, a, b, h, solver);
plot(t,yz(1,:));
xlabel('t');
ylabel('y');
grid on;
Obtenga la solución T(x) para una barra de 10m con T(0)=240 y T(10)=150
2
Replace the derivatives with the discrete versions and solve the resulting, simpler, algebraic equations.
Use the centered difference form of the second derivative accurate up to an error proportional to .
y''-4*y=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
1 - (2+4*h^2)*y(2) + y(3) =0
...
y(N-2) - (2+4*h^2)*y(N-1)+3 = 0
-(2+4*h^2)*y(2) + y(3) = -1
...
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);
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
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
where
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.
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
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
end