MATLAB: Setting up a Deflection Plot

plot

Hello
I am tryinng to calculate the amount of force for a deflection of a cantilever beam of known dimensions. I would like to plot the required forces calculated onto a line graph with Force on the Y axis, and Deflection in mm on the X Axis.
I have labelled each deflection, that i set, as deflectiona, deflectionb, deflectionc etc. I wanted to plot these against the output force on one graph. To demonnstrate how the force would change with deflection.
The script used to calculate the force vs deflections currently is:
% reference to variables can be found here
%https://www.quora.com/What-is-the-formula-of-a-deflection-cantilever-beam-point-load-at-mid-span
r = 0.005 ; % [m] radius of bar
P = 0.4; % [m] load applied on the beam
l = 0.012 ; % [m] lenght of beam
a = 0.008 ; % [m] position of load on beam (note l=a for load at tip)
E = 2.24e6; % [Pa] youngs modulas in Pa
I = pi*r^4/4; % [m^4] second moment of area
w = 0; % [N/m] uniformally distributed load (note w=0 for no loading);
delta_point_load = P*a^2*(3*l-a)/(6*E*I);
delta_UDL = w*l^4/(8*E*I);
total_delta = delta_point_load + delta_UDL; % Note that loads can be added together as the system is linear
fprintf('deflection from point load = %.16f mm\r',delta_point_load*1000)
fprintf('deflection from uniformly distributed load = %.16f mm\r',delta_UDL*1000)
fprintf('Total deflection = %.16f [mm] \r',total_delta*1000);
deflectiona = 0.002; %m
load_for_deflection = deflection* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflection,load_for_deflection)
deflectionb = 0.001; %m
load_for_deflection = deflection* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflection,load_for_deflection)
deflectionc = 0.0005; %m
load_for_deflection = deflection* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflection,load_for_deflection)
Can anyone help?

Best Answer

Try this, the way to plot F vs deflection
clearvars
clc
r = 0.005 ; % [m] radius of bar
P = 0.4; % [m] load applied on the beam
l = 0.012 ; % [m] lenght of beam
a = 0.008 ; % [m] position of load on beam (note l=a for load at tip)
E = 2.24e6; % [Pa] youngs modulas in Pa
I = pi*r^4/4; % [m^4] second moment of area
w = 0; % [N/m] uniformally distributed load (note w=0 for no loading);
delta_point_load = P*a^2*(3*l-a)/(6*E*I);
delta_UDL = w*l^4/(8*E*I);
total_delta = delta_point_load + delta_UDL; % Note that loads can be added together as the system is linear
fprintf('deflection from point load = %.16f mm\r',delta_point_load*1000)
fprintf('deflection from uniformly distributed load = %.16f mm\r',delta_UDL*1000)
fprintf('Total deflection = %.16f [mm] \r',total_delta*1000);
deflectiona = 0.002; %m


load_for_deflection1 = deflectiona* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflectiona,load_for_deflection1)
deflectionb = 0.001; %m
load_for_deflection2 = deflectionb* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflectionb,load_for_deflection2)
deflectionc = 0.0005; %m
load_for_deflection3 = deflectionc* P/total_delta;
fprintf('Load for deflection of %f m = %f N\r',deflectionc,load_for_deflection3)
Force = [load_for_deflection1 load_for_deflection2 load_for_deflection3];
def = [deflectiona deflectionb deflectionc]
plot(def*1000,Force); xlabel('Deflection [mm]');ylabel('Force');grid