# My plot command produces a blank graph, why?

조회 수: 2 (최근 30일)
Spencer . 2022년 10월 5일
댓글: KSSV . 2022년 10월 5일
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;
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없음 표시없음 숨기기
KSSV 2022년 10월 5일
Your variables are scalar i.e. a single value, how you expect a graph?

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Robert U 2022년 10월 5일
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;
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

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

R2022b

### Community Treasure Hunt

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

Start Hunting!