Hi everyone. My name is George and i am new to matlab. I need help to complete the following code, i am stuck. Please help.

1 view (last 30 days)
y=((-1/2)*g*t.^2)+(v*sind(x))*t

Accepted Answer

Walter Roberson
Walter Roberson on 2 May 2017
Your x is length 201 or so. Your t is length 5. What size are you expecting v*sind(x))*t to be?
The * operator is algebraic matrix multiplication. In order for A*B to work, size(A,2) == size(B,1) . Your v*sind(x) is going to be about 1 x 201, and your t is 1 x 5, but 201 ~= 1
If you were to use t.' * (v*sind(x)) then that would be (1 x 5) transposed * 1 x 201, which would be 5 x 1 * 1 x 201, and that would be valid and give a 5 x 201 result. But then you would have trouble adding it to the 1 x 5 that is ((-1/2)*g*t.^2)
I suggest you consider
[X, T] = ndgrid(x, t);
y = ((-1/2)*g*T.^2) +(v*sind(X)) .* T;

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!