My plot command produces a blank graph, why?

1 view (last 30 days)
Spencer
Spencer on 5 Oct 2022
Commented: KSSV on 5 Oct 2022
See below for the code. I expect to see two graphs but what I get is two blank graphs. Can someone tell me what I'm doing wrong?
% Clear everything and close everything
clear all;
close all;
% Determine the elongation of the cylinder as given by the equation w/o n
% Apply a load P (Pa)
P=40000000;
% Determine the length of the cone (m)
L = 1;
% Determine the radius (m)
c = .025;
% Determine the Modulus of Elasticity AKA Young's Modulus (Pa)
E = 31100000000;
% Determine the elongation
deformation =(P*L)/(2*3.141*c^2*E);
% Determine the elongation of the cylinder as given by the equation w/ n
% Determine the number of circlular cylinders
n = 6;
% Determine the length of each circular cylinder
L_n = L/n;
% Determine the radius of a single ciruclar cylinder
r = sqrt(((4/3)*3.141*c^2*L_n)/(3.141*L));
% Determine the area
A = 3.141*(r^2);
% Determine the elongation
deformation_n =(P*(L_n))/(A*E);
% Determine the error between the two results
error = -((deformation-deformation_n)/(deformation))*100;
% State the results
fprintf('The elongation of the cone without %g circular cylinders is %g m\n', n,deformation);
fprintf('The elongation of the cone with %g circular cylinders is %g m\n', n,deformation_n);
fprintf('The percent error calculated between the two is %g %%\n', error)
% Calculate the average axial stress
sigma = P/A;
% Calculate the average axial strain
epsillon = sigma/E;
% Plot the average axial stress and strain vs. length
% Axial stress vs. length
figure(1)
plot(sigma,L)
xlabel('Average Axial Stress [Pa]')
ylabel('Length [m]')
title('Average Axial Stress vs. Length')
% Axial strain vs. length
figure(2)
plot(epsillon,L)
xlabel('Average Axial Strain [Pa]')
ylabel('Length [m]')
title('Average Axial Strain vs. Length')
  1 Comment
KSSV
KSSV on 5 Oct 2022
Your variables are scalar i.e. a single value, how you expect a graph?

Sign in to comment.

Answers (1)

Robert U
Robert U on 5 Oct 2022
Hi Spencer,
Your plot contains a single point. You can make it visible with 'o' extension:
% Clear everything and close everything
clear all;
close all;
% Determine the elongation of the cylinder as given by the equation w/o n
% Apply a load P (Pa)
P=40000000;
% Determine the length of the cone (m)
L = 1;
% Determine the radius (m)
c = .025;
% Determine the Modulus of Elasticity AKA Young's Modulus (Pa)
E = 31100000000;
% Determine the elongation
deformation =(P*L)/(2*3.141*c^2*E);
% Determine the elongation of the cylinder as given by the equation w/ n
% Determine the number of circlular cylinders
n = 6;
% Determine the length of each circular cylinder
L_n = L/n;
% Determine the radius of a single ciruclar cylinder
r = sqrt(((4/3)*3.141*c^2*L_n)/(3.141*L));
% Determine the area
A = 3.141*(r^2);
% Determine the elongation
deformation_n =(P*(L_n))/(A*E);
% Determine the error between the two results
error = -((deformation-deformation_n)/(deformation))*100;
% State the results
fprintf('The elongation of the cone without %g circular cylinders is %g m\n', n,deformation);
The elongation of the cone without 6 circular cylinders is 0.327583 m
fprintf('The elongation of the cone with %g circular cylinders is %g m\n', n,deformation_n);
The elongation of the cone with 6 circular cylinders is 0.491375 m
fprintf('The percent error calculated between the two is %g %%\n', error)
The percent error calculated between the two is 50 %
% Calculate the average axial stress
sigma = P/A;
% Calculate the average axial strain
epsillon = sigma/E;
% Plot the average axial stress and strain vs. length
% Axial stress vs. length
figure(1)
plot(sigma,L,'o')
xlabel('Average Axial Stress [Pa]')
ylabel('Length [m]')
title('Average Axial Stress vs. Length')
% Axial strain vs. length
figure(2)
plot(epsillon,L,'o')
xlabel('Average Axial Strain [Pa]')
ylabel('Length [m]')
title('Average Axial Strain vs. Length')
I assume you try to perform a 1D finite element calculation and visualize the results. Maybe you should have a look into the Matlab documentation under language fundamentals to get familiar with the concept of vector calculus.
Your code does not resolve the single node parameters but merely one node.
Kind regards,
Robert

Categories

Find more on Stress and Strain in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!