MATLAB: Calculate velocity from position and time differentiablehomeworkloops derivatives velocity I have to write a program to calculate the velocity given position and time in two arrays. Best Answer pos = rand(100,1) ;t = 1:100 ;v = zeros(length(t)-1,1) ;for i = 1:length(t)-1 v(i) = (pos(i+1)-pos(i))/(t(i+1)-t(i)) ;end Related SolutionsMATLAB: Discretization of position and velocity First, the condition if 0 < x(1) < 2*piis not doing what it seem it does. The correct itif 0 < x(1) && x(1) < 2*piBeside, why do you use the if block when you are using mod function which will automatically wrap all values in the interval [0,2*pi]. Check the following codefunction s = discretize_state(x, par) % TODO: Discretize state. Note: s(1) should be % TODO: position, s(2) velocity. x(1) = mod(x(1), 2*pi); s(1) = round(x(1)/(2*pi)*(par.pos_states-1) + 1);end MATLAB: Indexing in a while loop Your lineatot(i)=athrust(i)-ag; % total accelerationdoes not define an equation. It is executed only once, with the current value of i, so atot becomes a scalar.Then in your line v(i+1)=v(i)+((atot(i+1)+atot(i))/2)*dt;on the first iteration you have the problem that atot(1+1) does not exist.After your while loop, nofuel_pos = find(mfuel <= 0, 1); and then you can index your arrays at nofuel_pos or nofuel_pos - 1 as appropriate. Related QuestionVelocity graph from position graphPlotting a moving particle in a box with elastic collisionsVelocity,Acceleration,Angle
Best Answer