Finite Element MATLAB Code for Solving Boundary Value Problems

Click For Summary
The discussion centers on formulating a MATLAB code to solve a boundary value problem defined by a differential equation with specific boundary conditions. The variational formulation is established, and a MATLAB plot is generated under different boundary conditions. The user seeks assistance in modifying the existing code to incorporate the boundary condition at x = 3, specifically needing to adjust the stiffness matrix and load vector. Key points include the need to modify the matrix K and the load vector bd to reflect the correct boundary terms. The conversation highlights challenges in implementing these changes effectively.
squenshl
Messages
468
Reaction score
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:
Physics news on Phys.org
I am completely lost.
 
Question: A clock's minute hand has length 4 and its hour hand has length 3. What is the distance between the tips at the moment when it is increasing most rapidly?(Putnam Exam Question) Answer: Making assumption that both the hands moves at constant angular velocities, the answer is ## \sqrt{7} .## But don't you think this assumption is somewhat doubtful and wrong?

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
8
Views
2K
Replies
12
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
9
Views
2K