Finding distance from a projectile.

What is each line is doing on this code?
D=[1 xi(end);1 newx];
b=[yi(end);newy];
a=D\b
Distance = (-a(1)/a(2))
newx = Distance;
newy = 0;
b=[ui(end);newu];
a=D\b;
u2 = (a(1)+a(2)*Distance);
newu = u2;
b=[vi(end);newv];
a=D\b;
v2 = (a(1)+a(2)*Distance);
newv = v2;
newv = -(newv*COR);

Answers (1)

Adam Danz
Adam Danz on 29 Mar 2021
Much of this is basic Matlab syntax that should be understood in order to do almost anything in Matlab. Take some time to go through the Matlab Onramp to get caught up.
xi(end) is indexing the variable xi, retrieving is end or last value.
D=[1 xi(end);1 newx] is creating a 2x2 matrix.
a=D\b - see mldivide
The rest is either indexing, creating of matrices or arrays or basic mathematics.

Asked:

on 29 Mar 2021

Answered:

on 29 Mar 2021

Community Treasure Hunt

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

Start Hunting!