TOMS
% Two‑Object Motion Simulation with Distance + Speed + Energy Tracking
steps = 50;
A.pos = [0,0]; A.vel = [1,0.5];
B.pos = [10,5]; B.vel = [-0.5,-0.2];
for t = 1:steps
A.pos = A.pos + A.vel;
B.pos = B.pos + B.vel;
dist = sqrt( (A.pos(1)-B.pos(1))^2 + (A.pos(2)-B.pos(2))^2 );
speedA = sqrt(A.vel(1)^2 + A.vel(2)^2);
speedB = sqrt(B.vel(1)^2 + B.vel(2)^2);
KE_A = 0.5 * speedA^2;
KE_B = 0.5 * speedB^2;
fprintf("Step %d\n", t)
fprintf(" A: [%.2f, %.2f] | Speed: %.2f | KE: %.2f\n", A.pos(1), A.pos(2), speedA, KE_A)
fprintf(" B: [%.2f, %.2f] | Speed: %.2f | KE: %.2f\n", B.pos(1), B.pos(2), speedB, KE_B)
fprintf(" Distance: %.2f units\n\n", dist)
end
1
1 comment
Danny Ledbetter
1
TOMS
powered by
Danny Ledbetter
skool.com/danny-ledbetter-4440
Is it to good to be true
Build your own community
Bring people together around your passion and get paid.
Powered by