Clear Filters
Clear Filters

Code runs but no graphical output

2 views (last 30 days)
I am trying to plot the deflection of a beam using MATLAB. My code runs but there is no output on my graph. I am using "for" operation rather than an array, because the array was producing errors. The code is as follows:
E = 200000; % Young's Modulus in N/mm^2
I = 416.667; % Moment on Inertia in mm^2
P = 600; %Applied force in N
Q = 1200; %Applied force in N
L = 3000; %Length of Beam in mm
b = 1000; %Applied location in mm for 600 N
a = 2000; %Applied location in mm for 1200 N
for x=0:10:3000
V = ((-P * b .* x) / (6 * E * I * L)) * (L^2 - b^2 - x.^2) + (((-Q * a .* x) / (6 * E * I * L)) * (L^2 - a^2 - x.^2));
end
plot (V,x)
xlabel 'Distance (mm)'
ylabel '(Deflection mm)'
I have attached a picture of the graph as well as the MATLAB script. Any assistance would be much appreciated!

Accepted Answer

Walter Roberson
Walter Roberson on 1 Dec 2023
E = 200000; % Young's Modulus in N/mm^2
I = 416.667; % Moment on Inertia in mm^2
P = 600; %Applied force in N
Q = 1200; %Applied force in N
L = 3000; %Length of Beam in mm
b = 1000; %Applied location in mm for 600 N
a = 2000; %Applied location in mm for 1200 N
xvals = 0:10:3000;
num_x = length(xvals);
for xidx = 1 : num_x
x = xvals(xidx);
V(xidx) = ((-P * b .* x) / (6 * E * I * L)) * (L^2 - b^2 - x.^2) + (((-Q * a .* x) / (6 * E * I * L)) * (L^2 - a^2 - x.^2));
end
plot (xvals, V)
xlabel 'Distance (mm)'
ylabel '(Deflection mm)'
  1 Comment
Peter Bohlen
Peter Bohlen on 1 Dec 2023
Thank you!! Looks like I did not set up the "for" loop correctly.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!