Completed a Heatmap and collected some data on the programs speed. The heatmap creates a grid of 50 x 50,angle x speed, and represents them using different colours to make it more easier to spot patterns. At each grid, there is one combination of speed and angle. E.g. 50m/s at 12 degrees, the colour shows the projectile range output from these inputs. Yellow represents long range,(as seen on the right of the image). We can clearly see the region at which the range is maximised( range grows with speed). Since drag is also involved in this, we can see that every speed has a omptimised angle which gives it the max range. IF this were to have no drag, all speeds would be optimised at 45 degrees.
I also plotted a graph of optimal angle and speed, whichs hows which angle gives the maximised range at a certain speed. The graph shows that as speed increases, drag increases and so the optimum angle moves away from 45 degrees(the optimum with no drag). Its not a smooth curve due to background noise due to tolerance not being exact.
The final table shows some tests i did which recorded the time the heatmap took to plot, there were few anomolies such as 50x50 one, which doubled from its First try ~60s. This is mainly due to background variance, such as other softwares running on my pc, which are using my cpu.
Monte carlo implementation. Running the simulation over random values of inital velocity and angle and height, to display the probabilities of different range values. This shows how likely the projectile will land at a certain area, which can be set as an target. This is important since projectile motion is never the same, even with same parameters, practically, it will not land exactly at the same spot, mainly because of shifting environments such as air resistance. So calculating ranges for different inital parameters(close to a certain mean) helps identify where the projectile may land(never 100% certain)
Succeeded in making a optimial angle calculator, which calculates the lowest possible angle to horizontal teh projectile should make to reach a target(a distance away) within some tolerance, travelling at a known inital velocity. . I then decided to plot a graph of optimal angle with max range. I also plotted a graph of speed against target/ranges. I used targets 30m, 60m, 45m, 90m, and calculated the lowest possible velocity and the angle which causes projectile to hit the target within tolerance. Originally, I though to loop through each value and try out combinations, which resulted in a very slow program, since the rk4 function was being called over 10000 times, given each call also had a dt = 0.01s, it took around 200s just to output the optimum angle. After that, I switched to programming a binary + tenary search which solved it in much quicker time <25s. To speed it up even more, I used my adaptive time model that i created earlier, this reduced the fixed dt= 0.01, reducing the total number of cycles needed to scan through whole motion
Tried to show the emperical order of the 3 methods with no drag, but only euler gave me its correct order (1). Heun and RK4 were identical as expected in a vacuum, they had order of 0.93. I researched the reaosn why it was not 2, and found that the landing-point linear interpolation error was the cause of it.
In the graph you can see how the error decreases with lower dt, and increases as dt increases. Expected.
Added adaptive time, so dt shortens for regions where more information is available/lots of change, but increases in regions where less information is available/lack of change. Plotted 2 graphs showing adaptive time, one shows the projectile trajectory with dt shown/marked. YOu can see its not constant like the previous ones. Anohter graph showing clearly how much the time step changes. It works on growth factors and decay factors(depending on error size). Last two graph show KE, PE and Total energy of the projectile with drag and no drag, showcasing that energy is dissipated to the surrounding with drag ( as heat). With no drag, total energy remains constant(graph shows a partial straight line due to error build up of numerical method over 7 minutes and overshooting the ground inaccuracies.)
Added wind to my model. Since wind affects only horziontal componenet in this case, the two winds were relatively easy to integrate into the acceleration function. Here are the graphs showing the wind in effect, when Projectile is at 45m/s, angle of 45 to horziontal and under gravitational acceleration of 9.81.
Unfortunately I was not able to add the Cross wind feature which I wanted to add. It involved adding a z-axis, since cross wind hits projectile perpendicularly. I am running low on time, this project is only supposed to run during holidays before school starts.
I decided to implement my drag rk4 model on earth, mars and the moon. This part was mainly integrating a system which uses different gravity values and air density values for different planets(which i got off google), into the rk4 model that i made previously. Due to the moon having 0 air density, the model predicted a graph with no drag, identical to the anaylitical curve in a vacuum. For mars, I learnt that the surface has a 11km thick layer of co2, which decreases with altitude(a decay function). I also included this to vary the drag for different altitude for the mars model.
Here i have compared the 3 models, with same initial parameters. In the 2nd graph, Im only comparing mars and earth to see how big of an effect drag has on the projectile.
Found few bugs in my program when i enabled input parameters. BEfore I had it set to a constant for ease. Once i changed the inputs, the Eulers method seemed to perform better than heun, which shouldnt be the case. I managed to find a bug in my Heun function(acceleration wasnt being updated in each turn), and now it works fine.
Completed implementation of Drag into my the 3 models. I used quadratic drag with the projectile being modelled as an sphere representing an apple. I tried my best to get the actual cross sectional area and the coefficient of drag of an average apple. Mass density i collected off google. Using the drag function that i made(implements quadratic drag formula), I calculated the acceleration components of the projectile. My main purpose was to show clearly that RK4 method is much more accurate with drag as compared to heun or euler’s method. AFter implementing drag and calculating acceleration at each stage in each method, i sketched few graphs using matplotlib. First graph was a simple trajectory graph of all the methods. I used RK4 method with a very small dt (1e-5), as an reference/analytical curve. After this i decided to plot the error curve between RK4 and heun method, i could clearly see that the two methods start to diverge with drag. Highest difference is when the velocity is at its maximum(largest drag), and the lowest difference is when velocity is very small/0, which means drag is almost 0. This gives similar results to the previous model with no drag(in which both heun and rk4 were replicas of one another/identical). Finally i did few plots of the methods with different time steps, and you can clearly see 0.5s is too big of a dt and ends up overshooting by a large amount. Finally, to clearly showcase the difference in empirical order, I decided to plot a range difference/error curve with both log and non-log axis. This range difference was calculated using the analytical curve. From thsi we can see that rk4 gives the lowest error, then followed by heun and finally euler, which gives the most error, highlighting their empirical order. Unfortunately, i did not manage to calculate the precise emprical order(through gradient) due to interpolation error at the landing boundary interfering with the fit.
Just finished the implementation of RK4 method to my vacuum projectile motion. Since acceleration is constant, the RK4 method is under utilized, and so produces a exact replica of the heun graph. This is to be expected since constant acceleration leads to RK2 and RK3 being the same quantity, and therefore the formula simply becomes heun’s method. I plotted two graphs, one was the trajectory of the 3 methods, and you can clearly see euler’s method starts to drift away slowly from the heun and RK4 curve. This is even more clear in the error graph with log axis. The large curve of the euler’s error shows how quickly the error accumulates, as compared to the rough curve of the heun and RK4 method. This roughness is noise caused by the program’s mathematical rounding limits. The error is so small that the program is not able to properly round it. (floating point arithmetic noise). AFter this, I will most likely be implementing drag.
I have just finished implementing Heun’s method which builds on Euler’s First order method. Rather than using the velocity of the previous time step, it averages the velocity of the previous and the current time step, and uses it to calculate the y displacement. Similar to my previous log, I made 5 main graphs. The first graph(Heun Step size comparison) shows how the Y value varies with different time step values. 0.5s produces the lowest resolution and hence the blocky line rather than a smooth curve. The next 4 graphs showcase the trajectory of the object analytically calculated using motion equations vs using Heun’s method. The last two graphs portray the error this method produces compared to the time/dt. This error is almost negligible and is mainly caused by the low sampling resolution rather than the method’s inaccuracy. This clearly highlights how much better performing this method is compared to Euler’s method.
Finished Part 3 of my Project. Here are the results for Part 1 - 3. Part 1 was simple simulation/graphical display of a projectile motion with inputted parameters such as inital velocity, acceleration, angle with the xaxis. Display was shown in both XvsY and Velocity-Time graph. Part 2 and 3 showcase Euler’s First order method. Graph of different time steps and how they differ from the ‘analytical’/projectile motion in a vacuum. Picture 3, shows 4 different graphs. Last graph shows how the error increase in max height changes with time(linearly). Next Part will consist of Heun’s method/Improved Euler’s method.