3 Errors involving linespace and multiplication symbol
3 ビュー (過去 30 日間)
古いコメントを表示
Trying to code a projectiles motion from start to when it hits y=0. All the numbers/data is in. Part of the assignment is to create user-defined inputs as you'll see in the code. Problem i'm having is without any of the user inputs, the code runs fine. Once I insert user defined inputs, I get 3 errors.
The errors are:
Error using .*
Matrix dimensions must agree.
Error in linspace (line 30)
y = d1 + (0:n1).*(d2 - d1)/n1;
Error in DummyCode (line 22)
t = linspace(0, tend, 1000);
I made a dummy file that's the exact same code as my assignment just without my comments,has the same errors, here it is:
a = input('45');
b = input('0');
c = input('0');
d = input('90');
Angle_deg = d;
Angle_rad = Angle_deg * pi/180;
V0 = a;
Vox = V0 * cos(Angle_rad);
Voy = V0 * sin(Angle_rad);
Y0 = c;
X0 = b;
g = -9.81;
ax = 0;
ay = g;
tend = (-Voy - sqrt(Voy^2 - 4.*(.5.*ay).*Y0))/(2 .*((.5).*ay));
size(tend);
t = linspace(0, tend, 1000);
x = X0 + V0*t + .5 * ax * t.^2;
y = Y0 + V0*t + .5 * ay * t.^2;
plot(x,y)
0 件のコメント
回答 (1 件)
Walter Roberson
2017 年 9 月 21 日
I do not get any error when I run that code and answer to the input prompts with the value printed out in the prompt.
However I suspect that the actual input mechanism you are using is something like inputdlg(), which does not return numbers: it returns a cell array of character vectors.
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!