In a tutorial I was running today, the following problem came up a few times.
The code was something like this
x = [ x0 + v*cosd(theta) * t, y0 + v*sind(theta) * t + .5 *g * t^2]
However, when you output x, it had 3 entries with a zero before the two calculated values. I have no idea how that happened. I restyled the same code exactly and this problem disappeared. Could this be some sort of bug with MATLAB?
In matlab if you combine a vector with a scalar the resulting value is a vector. For example:
So lets break down your equation:
into:
AandBmust both be scalars forxto be1x2. Your result is 1×3 because one of your variables because eitherAorBis 1×2. This is the result ofx0,v,theta,t,y0, orgnot being a scalar but a1x2vector.My suspicion is that
g,x0, ory0, is the culprit as these variables are unique to a single equation. So I’d start by checking the size of these values. However without knowing the values of your variables I can’t be sure.