% Galerkin deflection for a simple beam % Galerin G1, G2 clear x = 0:.1:1; p1 = (x .*x- x)/2; p2 = -4/pi^3*sin(pi*x); err = (1 - p1 ./p2)*100 % print the results % fprintf('\n Galerkin G1-2 ') % fprintf('\n Your name, ES 301, ') disp(date) fprintf('\n x approx exact\n') fprintf('\n Distance Quad Exact Error \n') for i = 1:length(x) fprintf(' %3.1f %7.4f %7.4f %8.4f \n', ... x(i),p1(i),p2(i),err(i)) end fprintf('\n') plot(x,p1,x,p2) title('Galerkin G1-G2, Sin Shape Function') xlabel('Beam length') ylabel('Deflection'), grid gtext('Approx'); gtext('Exact') % Distance Quad Exact Error % 0.0 0.0000 0.0000 NaN % 0.1 -0.0450 -0.0399 -12.8807 % 0.2 -0.0800 -0.0758 -5.5021 % 0.3 -0.1050 -0.1044 -0.6054 % 0.4 -0.1200 -0.1227 2.1942 % 0.5 -0.1250 -0.1290 3.1054 % 0.6 -0.1200 -0.1227 2.1942 % 0.7 -0.1050 -0.1044 -0.6054 % 0.8 -0.0800 -0.0758 -5.5021 % 0.9 -0.0450 -0.0399 -12.8807 % 1.0 0.0000 -0.0000 100.0000