3 Errors involving linespace and multiplication symbol

2 次查看(过去 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)

回答(1 个)

Walter Roberson
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.
  1 个评论
Moe
Moe 2017-9-22
Yeah I ended up figuring it out, in my inputs at the top I entered values where I should of put in questions/text to the user like "Insert velocity", that ended up fixing it and getting it running. Thanks for the answer though.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by