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!