Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Have already solved part A and the practical solution is: -x^2/6 + L^2/3*(x) CODE TO BE ALTERED AS PER PARTS B-D % This code solves
Have already solved part A and the practical solution is: -x^2/6 + L^2/3*(x)
CODE TO BE ALTERED AS PER PARTS B-D
% This code solves the BVP u''(x) + p(x) = 0 using Galerkin FEM clear all; %%%%%%%% Preliminary variables %%%%%%%% N=5; % Number of node points (not elements). L=1; dx=L/(N-1); x=0:dx:L; p=ones(N,1).*x'; % This is p(x) in the ODE. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create the trial functions psi and their derivatives dpsi psi=zeros(N,length(x)); dpsi=zeros(N,length(x)); [psi,dpsi] = psiterms(x, dx, N, psi); % Having a look at the psi test functions figure(1); for i=1:N plot(x,psi(i,:),'color',rand(1,3)) hold on end axis([0 1 0 1]) xlabel('$x$','Interpreter','latex','Fontsize',28) ylabel('$\psi_{i}$','Interpreter','latex','Fontsize',28) title('Linear test functions $\psi_{i}$','Interpreter','latex','Fontsize',28) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Calculating the entries of the matrix A by simple integration % The diagonal entries A=zeros(N,N); for i=1:N if i==1 A(i,i)=dx*max(abs(dpsi(i,:)))^2.0; elseif i==N A(i,i)=dx*max(abs(dpsi(i,:)))^2.0; else A(i,i)=2.0*dx*max(abs(dpsi(i,:)))^2.0; end end % The off-diagonal entries for i=1:N for j=1:N if i~=j & abs(i-j)
MATLAB FUNCTION USED IS BELOW:
function [psi,dpsi] = psiterms(x,dx,N,psi) for i=1:N if i==1 psi(i,x>=x(i)&x=x(i)&xx(i-1)&xx(i-1)&xx(i-1)&xx(i-1)&xx(i)&xx(i)&x=x(i)&x=x(i-1)&x=x(i-1)&xx(i)&x Problem 1 (The only problem!) The Matlab script FEM-m' has been created for you to have a play with. Make sure you also have the function file psiterms.m' in the same folder that you are running FEM.m from! Most of the hard work has been done for you already! It solves the BVP described in the notes d2u p(r) 30, u (0) 3 u(L) 30, (1) dac2 for the simple choice of p(z) r, for 0 S z S 1. The code has been set up with an initial choice of 5 rid elements that is 5 nodes at the points zi 0, 0.25, 0.5, 0.75 and 1 Therefore in this caseN (A is a 5 x 5 matrix, f and u are vectors of length 5 x 1) and the code solves the linear system, where u is the vector of coefficients un which are later used to build the FEM numerical solution in, as described in the background material. The code works by firstly defin- ing the r grid, step size and number of elements. It then calculates the linear trial functions, whi, and their derivatives, as defined in the notes. The entries of the matrix A and the vector f are then determined by equations (4) and (5). Your task is as follows: Part a) Calculate the exact solution to the above problem (with a pen and paper) taking into account the boundary conditions! Input this solution somewhere into your script Part b) Next we will finalise the FEM numerical solution with which to compare to the above exact solution. Firstly, as we do not know the values of du/da at the boundaries (we only have the conditions u (0) u(1) 0) we cannot fully evaluate the outer two terms of equation (5) in the notes. Therefore we must delete the first and last row and first and last column of the matrix A, the first and last entry of the vector f and the Problem 1 (The only problem!) The Matlab script FEM-m' has been created for you to have a play with. Make sure you also have the function file psiterms.m' in the same folder that you are running FEM.m from! Most of the hard work has been done for you already! It solves the BVP described in the notes d2u p(r) 30, u (0) 3 u(L) 30, (1) dac2 for the simple choice of p(z) r, for 0 S z S 1. The code has been set up with an initial choice of 5 rid elements that is 5 nodes at the points zi 0, 0.25, 0.5, 0.75 and 1 Therefore in this caseN (A is a 5 x 5 matrix, f and u are vectors of length 5 x 1) and the code solves the linear system, where u is the vector of coefficients un which are later used to build the FEM numerical solution in, as described in the background material. The code works by firstly defin- ing the r grid, step size and number of elements. It then calculates the linear trial functions, whi, and their derivatives, as defined in the notes. The entries of the matrix A and the vector f are then determined by equations (4) and (5). Your task is as follows: Part a) Calculate the exact solution to the above problem (with a pen and paper) taking into account the boundary conditions! Input this solution somewhere into your script Part b) Next we will finalise the FEM numerical solution with which to compare to the above exact solution. Firstly, as we do not know the values of du/da at the boundaries (we only have the conditions u (0) u(1) 0) we cannot fully evaluate the outer two terms of equation (5) in the notes. Therefore we must delete the first and last row and first and last column of the matrix A, the first and last entry of the vector f and the
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started