3 Errors involving linespace and multiplication symbol

4 visualizaciones (últimos 30 días)
Moe
Moe el 21 de Sept. de 2017
Comentada: Moe el 22 de Sept. de 2017
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)

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Sept. de 2017
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 comentario
Moe
Moe el 22 de Sept. de 2017
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by