I am getting error
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
Star Strider
2021-10-28
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.
.
0 个评论
Chris
2021-10-28
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.
0 个评论
Stephen23
2021-10-28
编辑:Stephen23
2021-10-28
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!