The downward deflection, y, of a cantilever beam with load, w, is calculated using the following formula
where x is the distance along the beam and E is the modulus of elasticity, I is the moment of inertia, and L is the length of the beam. The downward deflection will be calculated analytically, and compared to the numerical solution. The numerical solution will use the derived dy/dx to estimate the downward deflection, and an error analysis will compute the effectiveness of Euler's method.
Table 1: The following table shows all the given parameters.
The downward deflection of the beam is given in equation (i). To find the deflection at any point along the beam, any value of x from 0 to 6 can be plugged into equation (i). For example, the downward deflection at x=6 is found by plugging this x-value and the parameters into equation (i). Thus, the downward deflection at x=6 is 259.2m, as shown in equation (ii). Using MATLAB, the deflection of the beam over intervals of 0.5m and 1m was calculated.
1) Set parameters
2) Find analytical solution by plugging directly into equation (i)
3) Find numerical solutions for 2 different step sizes
4) Solve for the derivative at each 1 meter interval
5) Use a loop for summing the derivatives for step size of 1m
6) Solve for the derivative at each 0.5 meter interval
7) Use a loop for summing the derivatives for step size of 0.5m
8) Plot analytical and analytical solutions
9) Find error between each numerical solution and the analytical solution
10) Plot error
Euler's method was used to estimate the deflection of the beam using its derivative. Euler's method is a way to sum the derivative values and therefore, approximate the integral. In order to use Euler's method, first the derivative of equation (i) was taken. Then, the derivative was calculated at each interval and placed in a matrix using equation (iii).
Next, a loop was created to sum the previous derivative values at each matrix location. This gives an estimate of the deflection that can only be made more accurate by decreasing the step size. The process was repeated for a different smaller step size.
Figure 1: The figure above displays the plot of the points of the dy/dx graph using Euler's method. Visually, the red line resembles more of a curve than the blue line.
Figure 2: The figure above shows the percent error used between the analytical downward deflection and each iteration of the numerical deflection using Euler's method. The table shows that the percent error decreased as the number of intervals increased and the step size decreased.
Euler's method proved to be a successful way to estimate the downward deflection of the beam given a load. Using the analytical approach, the deflection was easily found by plugging the known values into equation (i). This approach gave the exact solution to the equation at each x-value. Using the numerical approach, deflection could be estimated with Euler's method. The smaller the step size used in Euler's method, the smaller the error from the actual deflection. Visually, this makes sense, because with more increments, the graph more closely resembles a curve. If the limit of the step size approaches 0, then this would yield the exact deflection of the beam. Euler's method is an effective way to estimate an integral, but using a relatively large step size will yield a high error.
%% Cameron King
%% 20 January 2020
% The purpose of this code is to compute the downward deflection of a
% cantilever beam with a uniform load using Euler's method. Since Euler's
% method only gives an estimate, this value will be compared to the
% analytical solution.
%% Set Parameters
E=(2*10^11); % Represents the modulus of elasticity (Pa)
I=2.5*10^(-4); % Represents the moment of inertia (m^4)
W=15000; % Represents the uniform load (N/m)
L=6; % Represents the length of the beam (m)
%% Analytical Solution
xa1=0:6; % The deflection will be calculated at each 1 meter interval along the beam.
% Each xa1 value will be plugged into the formula for ya1.
ya1=((W/(24.*E.*I)).*(xa1.^4))-(4.*(L.*(xa1.^3)))+(6.*(L.^2).*(xa1.^2));
xa2=0:0.5:6; % The analytical solution for each 0.5m interval.
ya2=((W/(24.*E.*I)).*(xa2.^4))-(4.*(L.*(xa2.^3)))+(6.*(L.^2).*(xa2.^2));
% Both analytical solutions are necessary when calculating error.
%% Numerical Solutions
x1=0:6; % A vector is created for each step.
dx1=1; % The step size is 1.
dy_dx1=(((W/(24.*E.*I)).*(4.*(x1.^3))-(12.*(L.*(x1.^2)))+(12.*(L.^2).*(x1))).*dx1); % dy_dx was deried from %the equation for y.
% a for loop is created to sum the values of dy_dx1 using Euler's method.
for a=1:7 % This is the length of the matrix dy_dx1.
y1(a)=sum(dy_dx1(1:a)); % This is Euler's method. All previous entries are summed to create a new %matrix, y1.
end
% The second iteration of Euler's method using a different step size.
x2=0:0.5:6; % A vector is created for each step.
dx2=0.5; % The step size is 0.5.
dy_dx2=(((W/(24.*E.*I)).*(4.*(x2.^3))-(12.*(L.*(x2.^2)))+(12.*(L.^2).*(x2))).*dx2); % dy_dx was derived %from the equation for y.
% a for loop is created to sum the values of dy_dx2 using Euler's method.
for b=1:13 % This is the length of the matrix dy_dx2.
y2(b)=sum(dy_dx2(1:b)); % This is Euler's method. All previous entries are summed to create a new %matrix, y2.
end
%% Results
hold on
plot(xa2,ya2,"b-s") % The analytical solution was plotted.
% Command to plot multiple data sets on the same graph.
plot(x1,y1,"g-s") % The first numerical solution was plotted.
plot(x2,y2,"r-sq") % The second numerical solution was plotted.
% The x-values using a step size of 1 were plotted against the deformation
% of the beam at each x-value. The hold function was used to keep the plot
% active for the next iteration of Euler's method.
title("Euler's Method Using Two Step Sizes");
ylabel("Deflection (m)");
xlabel("Length of Beam (m)");
legend ("Analytical Solution","Step Size = 1", "Step Size = 0.5")
% These final steps created the title, x-axis, y-axis, and legend for the
% graph.
hold off
%% Error
% Each of the two iterations of the numerical solution is going to be compared to the
% analytical solution in a percent error formula.
% percent error=abs((numerical-analytical)/(analytical))*100%
error1=abs((y1-ya1)./ya1).*100; % This is the error using the step size of 1.
error2=abs((y2-ya2)./ya2).*100; % This is the error using the step size of 0.5.
%% Error Plot
plot(xa1,error1,'b-s')
hold on
plot(xa2,error2,'r-s')
title("Percent Error Plot for Each Step Size");
ylabel("Percent Error");
xlabel("Length of Beam (m)");
legend ("Step Size = 1", "Step Size = 0.5")
% The lines above establish the title, y-axis, x-axis, and legend for the
% error plot.