NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
scaling_counterexample_backup.m
1 % Scaling counterexample
2 % Drew Sabelhaus
3 % 7-13-14
4 
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.
9 
10 clear all; clc; close all;
11 
12 % This disproves the following posulate:
13 % 10 * (length / time ^2) == (10 * length) / time^2
14 
15 % A simple particle in a projectile motion
16 m = 2; % kg. Note, this doesn't affect the simulation, obv.
17 v0 = 10; % m/s
18 g = 9.81; % m/s^2
19 theta = pi/2; % rad
20 
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)
24 
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.
28 
29 % For fun, let's simulate until the particle hits the ground again
30 % That will occur at tf = 2 * v0 * sin(theta) / g
31 
32 tf = 2 * v0 * sin(theta) / g;
33 
34 % Plot points along time from 0 to tf.
35 t = linspace(0, tf, 100);
36 
37 y = v0 * sin(theta) .* t - 0.5 * g * t.^2;
38 x = v0 * sin(theta) .* t;
39 
40 hold on;
41 plot(x,y);
42 title('Original, unscaled simulation');
43 xlabel('Horizontal length, meters');
44 ylabel('Vertical length, meters');
45 
46 % Now, for comparison, scale gravity.
47 % Recalculate when the projectile hits the ground.
48 g_scaled = 10 * g;
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;
53 
54 figure;
55 plot(x_new, y_new);
56 title('With only gravity scaled');
57 xlabel('Horizontal length, meters');
58 ylabel('Vertical length, meters');
59 
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;
65 
66 figure;
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');
71 
72 % HOWEVER! It should be clear here that there is an issue
void simulate(tgSimulation *simulation)