I have the following ODE
$$ u'' = -(1 + e^u), \quad u(0)=0,\quad u(1)=1$$
I want the divide the interval $[0,1]$ into $n-1$ equal subintervals each with length $h=1/(n-1)$ and we take approximate solution
$$ v(t,x) = \sum_{i=1}^{n} x_i t^{i-1} $$
polynomial of degree $n-1$ sothat $v(0,x)=0$ and $v(1,x)=1$, (boundary conditions are to be satisfied).
So, our goal is to determine $x_2,x_3,...,x_{n-1}$ interior points since we already know $x_1 = 0$. Once these are found, then we have an approximation to our true solution $u(t) \approx v(t,x)$.
My question is, how can we implement this in matlab? because solving such system is quite time consuming by hand.







To perform collocation, we introduce the regular discretization $t_i = i/n$ with $0\leq i\leq n$ of the domain $[0,1]$ (i.e., a set of $n+1$ collocation points). Then, we approximate $u$ by the polynomial function $p(t) = \sum a_k t^k$ of degree $n$ which satisfies the above problem at the collocation points. Therefore, $-p''(t_i) = 1 + \exp\!\big(p(t_i)\big)$ in the interior domain $1\leq i \leq n-1$, and $p(t_0)=0$, $p(t_n) = 1$ at the boundaries. In terms of the coefficients $a_k$, this system writes as $$ -\sum_{k=0}^{n-2} (k+2) (k+1) a_{k+2} \frac{i^k}{n^k} = 1 + \exp\left(\sum_{k=0}^n a_k \frac{i^k}{n^k}\right) , \qquad 1\leq i \leq n-1 $$ and $a_0 = 0$, $\sum a_k = 1$. This nonlinear algebraic system can then be solved numerically in terms of the coefficients $a_k$, e.g. by using Matlab's
fsolve.For example, if $n=2$, we consider the collocation points $\lbrace 0, 0.5, 1\rbrace$, and we look for the coefficients $a_0$, $a_1$, $a_2$. These coefficients satisfy $a_0 = 0$ and the algebraic system $$ \left\lbrace \begin{aligned} &{-2} a_{2} = 1 + \exp\left(\tfrac{1}{2} a_1 + \tfrac{1}{4} a_2\right)\\ &a_1 + a_2 = 1 \end{aligned}\right. $$ which real solutions obtained numerically $$ (a_1,a_2) \in \lbrace (2.78945, -1.78945), (10.6101, -9.61014) \rbrace . $$ are represented below:
One observes that such solutions are not necessarily unique. Comparison with Matlab's
bvp4cis given below, where the algorithm is initialized by the constant $0.5$:If initialization is performed with the constant $2.5$, then the higher solution is obtained.