Code runs but no graphical output

4 Ansichten (letzte 30 Tage)
Peter Bohlen
Peter Bohlen am 1 Dez. 2023
Kommentiert: Peter Bohlen am 1 Dez. 2023
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Dez. 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 Kommentar
Peter Bohlen
Peter Bohlen am 1 Dez. 2023
Thank you!! Looks like I did not set up the "for" loop correctly.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by