# MATLAB: Euler’s Method and Deflection of Cantilever Beam

eulersmethod

Hi, I'm trying to write the code to calculate the deflection of a beam using euler's method. The deflection of the beam is given as w/(24*EI)*(x^4-4Lx^3+6L^2x^2) and the derivative is w/(24*EI)*(4x^3-12Lx^2+12L^2x). This code works except the answers I am looking for are slightly off. So when x = 1.25, y = 3099, but right now I'm getting x = 2.5, y = 3099. Does anyone know why this is or can help me fix this?
``w = 21819;EI = 106;L = 5; % lengthh=1.25; % step's sizeN=5; % number of stepsy(1)=1;for n=1:N       y(n+1)= y(n)+h*(w/(24*EI))*(4*x(n).^3 - (12*L*x(n).^2) + (12*L^2*x(n)));x(n+1)=n*h;          % euler's method, using derivative of given functionendplot(x,y)``

``w = 21819;EI = 106;L = 5; % lengthN = 100; % number of stepsh = L/N; % step's sizeytrue = @(x)w/(24*EI)*(x.^4 - 4*L*x.^3 + 6*L^2*x.^2); % uniformly loaded cantilever beamy(1)=0;x(1) = 0;for n=1:N-1       y(n+1)= y(n)+h*w/(24*EI)*(4*x(n).^3 - 12*L*x(n)^.2 + 12*L^2*x(n));x(n+1)=n*h;          % euler's method, using derivative of given functionendplot(x,ytrue(x),x,y,'.'),gridxlabel('x'),ylabel('displacement')legend('true','Euler')``