Why are the lines not showing up on my graphs?

3 visualizaciones (últimos 30 días)
Anna Zito
Anna Zito el 25 de Mayo de 2020
Comentada: Star Strider el 25 de Mayo de 2020
g=9.81;
Ta=10;
mA=20;
for i=1:100
M=(i-1)*(30/99);
mB=4.05;
mC=M;
mD=M;
JC=0.005*M;
JD=JC;
JA=0.8055;
A=[mA 0 -1 1 0 0 0; (5*JA) 0 0.2 0 0 0 0; (10*JC) 0 0 -0.1 0 0.1 0; 0 mD 0 0 -1 -1 -1; 0 (10*JD) 0 0 0 -0.1 0.1; 0 mB 0 0 -1 0 0; -0.5 1 0 0 0 0 0];
B=[0; Ta; 0; (-mD*g); 0; (-mB*g); 0];
x=inv(A)*B;
aA(i)=x(1); aB(i)=x(2); FA(i)=x(3); TA(i)=x(4); TB(i)=x(5); TC(i)=x(6); TD(i)=x(7);
end
Mvector=linspace(0,30,100);
plot(Mvector, aA(i),'g',Mvector,aB(i),'b-.');
title('Acceleration');
legend('Disk A','Mass B');
xlabel('M (kg)');
ylabel('Acceleration (m/s^2)');
pause
plot(Mvector,aA(i),'g',Mvector,aB(i),'b-.');
title('Acceleration');
legend('Disk A','Mass M');
xlabel('M (kg)');
ylabel('acceleration (m/s^2)');
pause
plot(Mvector, FA(i),'k');
title('Plot 3');
xlabel('M (kg)');
ylabel('FA (N)');
pause
plot(Mvector,TA(i),'g',Mvector,TB(i),'b-.');
title('Plot 4');
legend('Cable A','Cable B');
xlabel('M (kg)');
ylabel('Tension (N))');
pause
plot(Mvector,TA(i),'g',Mvector,TC(i),'b:',Mvector,TD(i),'r-.');
title('Plot 5');
legend('Cable A','Cable C','Cable D');
xlabel('M (kg)');
ylabel('Tension (N)');
pause
plot(Mvector,FA(i)/(mA*g),'k');
title('Plot 6');
xlabel('M (kg)');
ylabel('mu');

Respuesta aceptada

Star Strider
Star Strider el 25 de Mayo de 2020
You are only plotting one point (that being the last point) and it is not possible to plot lines with only one point.
Try this:
Mvector=linspace(0,30,100);
figure
plot(Mvector, aA,'g',Mvector,aB,'b-.');
title('Acceleration');
legend('Disk A','Mass B');
xlabel('M (kg)');
ylabel('Acceleration (m/s^2)');
% pause
figure
plot(Mvector,aA,'g',Mvector,aB,'b-.');
title('Acceleration');
legend('Disk A','Mass M');
xlabel('M (kg)');
ylabel('acceleration (m/s^2)');
% pause
figure
plot(Mvector, FA,'k');
title('Plot 3');
xlabel('M (kg)');
ylabel('FA (N)');
% pause
figure
plot(Mvector,TA,'g',Mvector,TB,'b-.');
title('Plot 4');
legend('Cable A','Cable B');
xlabel('M (kg)');
ylabel('Tension (N))');
% pause
figure
plot(Mvector,TA,'g',Mvector,TC,'b:',Mvector,TD(i),'r-.');
title('Plot 5');
legend('Cable A','Cable C','Cable D');
xlabel('M (kg)');
ylabel('Tension (N)');
% pause
figure
plot(Mvector,FA/(mA*g),'k');
title('Plot 6');
xlabel('M (kg)');
ylabel('mu');
Also, you were overplotting each new plot on the previous one, erasing the previous one. Since it appears you want them on separate figures, this slightly revised code does that. If you want to plot all of them on the sane axes, use the hold function.
  7 comentarios
Anna Zito
Anna Zito el 25 de Mayo de 2020
That worked!!! Thank you so much! Youre amazing!!!!!!
Star Strider
Star Strider el 25 de Mayo de 2020
As always, my pleasure! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by