Matlab uppgift: The Bratu Problem
The Bratu problem is the boundary value problem -u'' = lambda*e^u; 0 < t < 1
for lambda > 0, subject to the boundary conditions, u(0) = u(1) = 0:
Depending on the parameter lambda, this nonlinear problem has two, one or no solutions.
For lambda = 1, it has exactly two solutions. One of them is easily computable,
the other one is hard to find. Your task is to approximate the solutions for lambda = 1
by different numerical methods.
1. Use the finite difference method with n equidistant interior nodes! Set h =
1=(n + 1) and ti = ih, for i = 0; : : : ; n + 1. The resulting system becomes
nonlinear in the discrete approximations yi. Plot the sequence of solutions
which you obtain for n = 1; 3; 7; and 15!
2. Try to find the second solution! Hint: Both solutions have positive initial
slope.
Solution:
m-fil 1:
function f = bratufkn(u);
n =15;
h = 1/(n+1);
A = eye(n)*(-2/h^2);
H = ones(1,n-1)*1/h^2;
A = A+diag(H,-1)+diag(H,1);
f = -A*u-exp(u);
m-fil 2:
options = optimset('TolFun',1e-8,'Display','iter');
n = 15;
A = ones(n,1);
A(n/2+.5,1) = 10
[u,fval,exitflag,output] = fsolve(@bratufkn,A,options)
u = [0;u;0];
h = 1/(n+1);
l = size(u);
for i = 0:n+1
l(i+1) = i*h;
end
plot(l,u,'r-',l,u,'go')
xlabel('t')
ylabel ('u')
title (' n = 15')
Nu är det så att jag har fått m-filerna av en kamrat men skulle behöva hjälp med att förstå de. Någon som vill bolla lite?