n = 10; L = 2; w = .3; d = .03; h = L/n; %define variables x = h:h:L; I = w*d^3/12; E = 1.3e10; g = 9.81; %downward force due to gravity A = zeros(n); %initialize the matrix A A(1,1:4) = [16 -9 8/3 -1/4]; %enter the fixed values for the matrix A(2,1:4) = [-4 6 -4 1]; A(n-1,n-3:n) = [16/17 -60/17 72/17 -28/17]; A(n,n-3:n) = [-12/17 96/17 -156/17 72/17]; for i = 3:n-2 %use for loops to fill in the remaining entries in matrix A for j = 1:n A(i,i-2) = 1; A(i,i-1) = -4; A(i,i) = 6; A(i,i+1) = -4; A(i,i+2) = 1; end end f = -480*w*d*g; fvector = f*ones(n,1); RHS = h^4/(E*I)*(fvector); y = zeros(n,1); ysolution = A\RHS; yactual = ((f/(24*E*I)).*x.^2.*(x.^2-4*L.*x+6*L^2))'; error = abs(ysolution - yactual); endpointerror = abs(ysolution(n) - yactual(n)); figure(); plot(x,ysolution,'ro',x,yactual); title('Plot of Approximate Solution vs. Correct Solution'); xlabel('x'); ylabel('y(x)'); figure(); semilogy(x,error,2,endpointerror,'ro');axis([0 2 0 10e-16]); title('Plot of Error'); xlabel('x'); ylabel('log(error)');