I am getting error

1 visualización (últimos 30 días)
Cameron Paterson
Cameron Paterson el 28 de Oct. de 2021
Editada: Stephen23 el 28 de Oct. de 2021
math error
t=linspace(0,15);
x=(3*t.^2-5)*(t.^3)*sind(t./2)-8*t+27;
v=6*t-2.5*(t.^3)*cosd(t./2)-15*t.^2*sind(t./2)-8;
a=1.25*t^3*sind(t./2)-15*t.^2*cosd(t./2)-30*t*sind(t/2)+6;
plot(t,x,'-',t,v,'--',t,a,'-.','linewidth',1)
title('StreamLine')
xlabel('Time')
ylabel('Velocity')
legend('bestoutside')
grid on

Respuestas (3)

Star Strider
Star Strider el 28 de Oct. de 2021
Use element-wise operations everywhere and it works —
t=linspace(0,15);
x=(3*t.^2-5).*(t.^3).*sind(t./2)-8*t+27;
v=6*t-2.5*(t.^3).*cosd(t./2)-15.*t.^2.*sind(t./2)-8;
a=1.25*t.^3.*sind(t./2)-15.*t.^2.*cosd(t./2)-30.*t.*sind(t/2)+6;
figure
plot(t,x,'-',t,v,'--',t,a,'-.','linewidth',1)
title('StreamLine')
xlabel('Time')
ylabel('Velocity')
legend('x','v','a', 'Location','bestoutside')
grid on
The legend call also needs to include the plotted variables, and the names appropriate to the values.
.

Chris
Chris el 28 de Oct. de 2021
In addition to dots in front of carets ( .^ ) and slashes ( ./ ), you need dots in front of the asterisks ( .* ) for elementwise multiplication.
Otherwise, Matlab attempts matrix multiplication.

Stephen23
Stephen23 el 28 de Oct. de 2021
Editada: Stephen23 el 28 de Oct. de 2021
You need to use array operations, not matrix operations (you missed this for multiplication):
t=linspace(0,15);
x=(3*t.^2-5).*(t.^3).*sind(t./2)-8.*t+27;
% ^ ^ ^
v=6*t-2.5*(t.^3).*cosd(t./2)-15*t.^2.*sind(t./2)-8;
% ^ ^
a=1.25*t.^3.*sind(t./2)-15.*t.^2.*cosd(t./2)-30.*t.*sind(t/2)+6;
% ^ ^ ^ ^ ^ ^
plot(t,x,'-',t,v,'--',t,a,'-.','linewidth',1)
title('StreamLine')
xlabel('Time')
ylabel('Velocity')
legend('Location','bestoutside') % I fixed this for you too
grid on

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by