Getting an error message and don't know how to fix

10 views (last 30 days)
I have code that looks like this
% The loop
for i=1:N-1
v=diff(z);
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
z(i+1) = z(i)+h*v(i+1);
end
the error message has come up like this in the command window
Error in particle (line 24)
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
No idea what ive done, its probably a really easy fix but im having a blonde moment. New to this stuff. Thanks :)
  2 Comments
Holly Martin
Holly Martin on 21 Nov 2019
Unable to perform assignment because the left and right sides have a different number of elements.
Error in particle (line 24)
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
Sorry- im so stupid sometimes haha

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 21 Nov 2019
Edited: the cyclist on 21 Nov 2019
abs(v)
is a vector, so the right-hand side is a vector. You are trying to put that into one element of v on the left-hand side.
Maybe you meant
abs(v(i))
there?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!