Why won't my graph plot?

조회 수: 1 (최근 30일)
Julie Miller
Julie Miller 2019년 10월 31일
답변: Daniel M 2019년 10월 31일
This is my code:
%use a for loop to set a range with increments
for d=0:0.1:20
%Find the length of cable 3 by plugging in the given distance
L=(100 + d^2)^(1/2);
%Write the equations for the tensile forces in the three cables
A=[0.348, -0.557, 0; -0.348, -0.239, (d/L); 0.870, 0.796, (10/L)];
C=[0; 0; 1000];
%Calculate the tensile forces
T=inv(A)*C;
%Find the maximum tensile force
M=max(T);
%Use the maximum tensile force to find the factor of safety
FS=1500/M;
end
plot(FS, d)

채택된 답변

Star Strider
Star Strider 2019년 10월 31일
You need to save the elements of ‘FS’ in order to plot them against vector ‘d’.
I slightly edited your code:
%use a for loop to set a range with increments
dv=0:0.1:20; % Define Vector
for k = 1:numel(dv)
d = dv(k);
%Find the length of cable 3 by plugging in the given distance
L=(100 + d^2)^(1/2);
%Write the equations for the tensile forces in the three cables
A=[0.348, -0.557, 0; -0.348, -0.239, (d/L); 0.870, 0.796, (10/L)];
C=[0; 0; 1000];
%Calculate the tensile forces
T=inv(A)*C;
%Find the maximum tensile force
M=max(T);
%Use the maximum tensile force to find the factor of safety
FS(k)=1500/M; % Save Results As Vector
end
plot(FS, dv)
Experiment to get different results.

추가 답변 (1개)

Daniel M
Daniel M 2019년 10월 31일
It did plot. Try this:
plot(FS,d,'bo')
It's just that FS and d only contain 1 element.
You need to understand how to store data from for loops.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by