I want to find a function which can calculate the 3 dimension euclidean distance.
I have 9 arrays: Dx; Vx; ax; Dy; Vy; ay; Dz; Vz; az. the size of 9 arrays are the same.each array is 1*100000
the start point x0 =(Dx(1) Dy(1) Dz(1)) = (100 150 125)
How can I creat a function/script to run the following function:
x = Dx + Vx*t + 1/2*ax*t^2;
y = Dy + Vy*t + 1/2*ay*t^2;
z = Dz + Vz*t + 1/2*az*t^2;
t = 2; % it is fixed
L = ((x(n)-x(n-1))^2+(y(n)-y(n-1))^2+(z(n)-z(n-1))^2)^(1/2);
Thanks for your time and helping. :D

 Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Feb. 2016

0 Stimmen

This will do those equations:
function L = CalcDistance()
Dx = rand(1,100000);
Dy = rand(1,100000);
Dz = rand(1,100000);
Vx = rand(1,100000);
Vy = rand(1,100000);
Vz = rand(1,100000);
ax = rand(1,100000);
ay = rand(1,100000);
az = rand(1,100000);
t = 2; % it is fixed
x = Dx + Vx*t + 1/2*ax*t^2;
y = Dy + Vy*t + 1/2*ay*t^2;
z = Dz + Vz*t + 1/2*az*t^2;
dx = diff(x);
dy = diff(y);
dz = diff(z);
L = sqrt(dx.^2+ dy.^2+ dz.^2);
Of course you would not use rand(), you'd use the actual arrays, wherever you got them.

4 Kommentare

Cheng Kang
Cheng Kang am 11 Feb. 2016
Thanks very much for your helping.
I have a further question, How can I set the starting point with this function, the start point is: x0 =(Dx(1) Dy(1) Dz(1)) = (100 150 125).
Torsten
Torsten am 11 Feb. 2016
How does the starting point come into play in the calculation of L ?
Best wishes
Torsten.
Image Analyst
Image Analyst am 11 Feb. 2016
You don't need x0. It's already in your D arrays at the first elements, so it's already taken into account in your L.
Cheng Kang
Cheng Kang am 11 Feb. 2016
Bearbeitet: Cheng Kang am 11 Feb. 2016
Thanks for your helping, my question is solved.
Have a nice day! :D
Kang

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by