Question: Write a program which takes as input the number of elements, the end points of each element, the degree of the polynomial, and boundary condition
Write a program which takes as input the number of elements, the end points of each element, the degree of the polynomial, and boundary condition information, and builds the matrix K and the load vector F. The outline of the program is as follows: function [K, Fl- buildkf (nelem , h, deg, alpha, beta gunma) % function which takes as input: % nelem-the number of elements % h(i), i-1, ,nelem-length of each element % deg-degree of the polynomial shape functions % alpha, beta,garmma vectors of length 2 which determine the % boundary conditions: alpha ( 1) *u"(0)-beta (1 ) *u(0)-gannna(1) alpha (2)u'(1)+-beta (2)u(1)-gamma (2) loop over the elements compute local element matrices ke and fe place them in the appropriate places in global matrix K and F end loop correct K and F for boundary conditions The governing system has the form of Eqn.(1): du(a) (r)u(x)- f(x) over domain 2(0, 1 du(0) Boundary conditions : addr) + Au(0) = "Yo You will need to provide external functions for the coefficients k, b, c and f and a Gauss- quadrature routine for doing the integration. You may also want to write functions which construct the shape functions and their derivatives on the master element. You do not need to consider shape functions with degree higher than 2. Test your program on the following problem. Take k 1+,c+x,b and f--2exp(x), u'(0)-2u(0)- -1, u(1) e. Take 8 equally spaced elements, with deg-2. Print the matrix K and the load vector F and submit in class. In addition, upload your code and results on blackboard. Part B Test your 1D finite element program on the following problems: 1. Take k 2 + x, b = c = 0 and f =-6-4x. Take as boundary conditions (1 + z)2. Your code should get this z, b = 1 and f = 3r2-5. Take as boundary conditions 3. Take b-0,k 2 for 2/3, u(0) (1) 0. Take u(0) = 1, u(1) = 4. The true solution is u solution exactly independent of the number of elements. u(0) = 1, u(1) = 4. The true solution is again u = (1 +z)2. f = 5, Verify that you obtain the solution: 2. Take k = 2 + z, c 4. Take k 1, b-c-0 and f .. 0.25"cos(TZ/2) with boundary conditions u(0) 1,(1)-/2. Show that the true solution is u(z)-Cos(x/2). Taking 4, 8, 16, and 32 elements, verify that the H error in the finite element solution is of second order and the L2 error is of third order. As for part B, plot numerical solution against analytical solution. Your mesh should be fine enough to get a match with analytical solution. Additionally for problem 4 plot errors against mesh size in log-log scale and compute numerical convergence rates. Submit all your results in class and upload your code on blackboard
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
