3 Errors involving linespace and multiplication symbol

5 Ansichten (letzte 30 Tage)
Moe
Moe am 21 Sep. 2017
Kommentiert: Moe am 22 Sep. 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)

Antworten (1)

Walter Roberson
Walter Roberson am 21 Sep. 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 Kommentar
Moe
Moe am 22 Sep. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by