1 % Scaling counterexample
5 % This basic simulation is designed to show, by counterexample,
6 % why use of nondimensional numbers is necessary for NTRT.
7 % Equivalently, this would show why the commutative property of
8 % multiplication does not apply to scaling of units.
10 clear all; clc; close all;
12 % This disproves the following posulate:
13 % 10 * (length / time ^2) == (10 * length) / time^2
15 % A simple particle in a projectile motion
16 m = 2; % kg. Note,
this doesn
't affect the simulation, obv.
21 % For a projectile, newton's 3rd law is
22 % F_x = 0 (no forces in x)
23 % F_y = -mg (one force is gravity)
25 % Recalling position vs. time equation, which is
26 % x(t) = x0 + v0 * t + 0.5 * a * t^2
27 % Here, a_y = g, a_x = 0.
29 % For fun, let's
simulate until the particle hits the ground again
30 % That will occur at tf = 2 * v0 * sin(theta) / g
32 tf = 2 * v0 * sin(theta) / g;
34 % Plot points along time from 0 to tf.
35 t = linspace(0, tf, 100);
37 y = v0 * sin(theta) .* t - 0.5 * g * t.^2;
38 x = v0 * sin(theta) .* t;
42 title(
'Original, unscaled simulation');
43 xlabel(
'Horizontal length, meters');
44 ylabel(
'Vertical length, meters');
46 % Now,
for comparison, scale gravity.
47 % Recalculate when the projectile hits the ground.
49 tf_new = 2 * v0 * sin(theta) / g_scaled;
50 t_new = linspace(0, tf_new, 100);
51 y_new = v0 * sin(theta) .* t_new - 0.5 * g_scaled * t_new.^2;
52 x_new = v0 * sin(theta) .* t_new;
56 title(
'With only gravity scaled');
57 xlabel(
'Horizontal length, meters');
58 ylabel(
'Vertical length, meters');
60 % Here
's the fun part: take that last simulation, and scale length,
61 % as we'd normally
do in NTRT.
62 length_scaling_factor = g_scaled/g;
63 y_new_scaled = length_scaling_factor * y_new;
64 x_new_scaled = length_scaling_factor * x_new;
67 plot(x_new_scaled, y_new_scaled);
68 title(
'With both gravity and length scaled, post-hoc');
69 xlabel(
'Horizontal length, units of meters * scaling const');
70 ylabel(
'Vertical length, units of meters * scaling const');
72 % HOWEVER! It should be clear here that there is an issue
void simulate(tgSimulation *simulation)