Borrar filtros
Borrar filtros

ERROR using plot. Vectors must be same lenght.

2 visualizaciones (últimos 30 días)
Paolo LEONARDI
Paolo LEONARDI el 23 de Ag. de 2019
Comentada: Paolo LEONARDI el 23 de Ag. de 2019
I have a problem with the final part of this code, I can't plot the last graphic. Thank you.
n=2000; % [rpm]
phi=0:2*pi/1000:2*pi; % [rad]
r=0.25; % [m]
l=0.57; % [m]
lam=r/l; % lambda
sb=r*(1+lam/4-cos(phi)-(lam*cos(2*phi))/4); % spostamento del pistone
syms x(ang);
x(ang)=r*(1+lam/4-cos(ang)-(lam*cos(2*ang))/4);
sb_sym=x(phi);
figure(1)
plot(phi,sb,'*',phi,sb_sym)
title('Grafico Spostamenti');
legend('spostamento [m]','spostamento:formula simbolica [m]');
grid on;
figure(2)
fplot(x,[0,2*pi])
title('Grafico Simbolico Spostamenti [m]');
syms x_dot(ang)
x_dot(ang)=diff(x(ang))
Om=n*((2*pi)/60); % omega [rad/s]
vb_sym=Om*x_dot(phi);
vb_num=Om*(diff(sb)./diff(phi));
vb=Om*r*(sin(phi)+(lam*sin(2*phi))/2);
figure(3)
plot(phi,vb,'*',phi(1:end-1),vb_num,phi,vb_sym)
title ('Grafico Velocità')
legend('velocita [m/s]','velocita:formula simbolica [m/s]');
grid on;
ab=(Om^2)*r*(cos(phi)+lam*cos(2*phi));
ab_num=(Om^2)*(diff(vb)./diff(phi));
syms vb(ang);
vb(ang)=Om*r*(sin(ang)+(lam*sin(2*ang))/2);
vb_dot(ang)=diff(vb(ang));
ab_sym=vb_dot(ang);
figure(4)
plot(phi,ab,'*',phi(1:end-1),ab(1:end-1),ab_num,phi,ab_sym) *ERROR using plot. Vectors must be same lenght
title('Grafico Accelerazione')
legend('accelerazione[m/s^2]','accelerazione:formula simbolica [m/s^2]');
grid on;

Respuesta aceptada

Ted Shultz
Ted Shultz el 23 de Ag. de 2019
you appear to have two errors on that plot line:
1) ab_sym is a symbolic expression - did you mean to exclude this?
2) what did you intend for the x axis of the ab_num plot?
You can make it clearer what you are trying to do if you change that one line to:
plot(phi,ab,'*')
hold on
plot(phi(1:end-1),ab(1:end-1))
plot(phi(1:end-1), ab_num) % assume x axis is phi(1:end-1)
% plot(phi,ab_sym) % not sure what intended
  1 comentario
Paolo LEONARDI
Paolo LEONARDI el 23 de Ag. de 2019
Thank you very much. I was trying to concentrate all that variables in one graphic to make a confrontation, your answers were both correct, I plotted them in two graphics, hope my professor won't argue with that...

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