- #1
squenshl
- 479
- 4
Homework Statement
Consider the problem
$$-u''\left(x\right) = 1, \;\; 0 < x < 3, \;\; u \left(0\right) = 0, \; -u' \left(3\right) = u\left(3\right)+1.$$
Formulate a MATLAB code to produce the solution and plot the solution from 0 to 3.
Homework Equations
The Attempt at a Solution
Multiply by a function v and integrating from 0 to 3 to get
$$v \left(3 \right)u \left(3 \right)+v \left(3 \right)+u'\left(0\right)v \left(0 \right)+\int_0^3 v'u' \; dx = \int_0^3 v \;dx$$
In this case the bilinear form is
$$a\left(u,v\right) = v \left(3 \right)u \left(3\right)+u'\left(0 \right)v\left(0 \right) + \int_0^3 v'u' \; dx$$
and the linear functional is
$$F(v) = \int_0^3 v \; dx - v\left(3\right).$$
The variational formulation is to find u such that $$a\left(u,v\right) = F(v).$$
I produced a MATLAB plot when we have the following boundary conditions
$$u(0) = 0, u(3) = 1$$
given in the attached file. Note that here we have the full stiffness matrix K, which involves the integrals
$$\phi_0 \quad \text{and} \quad \phi_n$$
and is useful for Neumann and Robin BVPs. The actual coefficient matrix A for the Dirichlet BVP is the matrix obtained by deleting the first and last rows and columns of K. The function f is defined
separately given by f.m. How do I alter the code to incorporate the boundary conditions at x = 3. I know that there must be an extra part in the line K = spdiags... to make the matrix of boundary terms in a(u,v) and we delete the line A = ... and we alter the 3 lines that make the load vector bd = ... given in F(v). Someone please help.
Attachments
Last edited: