Least action and numerical integration #5
Replies: 54 comments 6 replies
-
|
I tried a number of different functions with the same initial conditions that used the same IC, that being several different harmonic expressions as well as an exponential function just to see how that would impact the calculation for the integral of the action. Here are the basics of what I had found:
|
Beta Was this translation helpful? Give feedback.
-
|
I tested several different trial functions that all used the same initial conditions as the harmonic oscillator and compared their total action by integrating the Lagrangian. As expected, the exponential function produced the largest action, which makes sense since it deviates strongly from the system’s natural motion. Adding non-harmonic features to otherwise oscillatory functions also increased the action noticeably, showing how sensitive the action is to added complexity in the motion. it was interesting to experiment with how different choices affect the result. |
Beta Was this translation helpful? Give feedback.
-
|
I keep getting an unavailable server issue, and cant open the notebook. Has anyone else gotten this or have ideas how to fix it? |
Beta Was this translation helpful? Give feedback.
-
|
Instead of trying a handful of functions to test the principle of least action, I decided to automate the approach to this problem using Julia. I started with the analytical solutions in the lecture: I then created a general form for a trial path that adds a scaled perturbation onto the analytical solution while still matching its boundary conditions: This works because the sine term is zero at the initial time, For each trial path, I then calculated the velocity, which allowed me to find the lagrangian. Finally, I numerically integrated the lagrangian, as shown in the lecture video, to find the action for each trial path. Plotting the action for each trial path versus its respective scalar, According to the principle of least action, we would expect that the action is minimized for the analytical solution |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I started testing various mathematical functions, all from the same initial conditions, to see how they affected the calculated value of the action integral. The key results were: The exponential function produced the largest action integral area. This was an expected outcome and was primarily tested out of curiosity. In general, introducing more non-harmonic elements into a system's motion tends to significantly increase the area under the action curve. While many functions can be made to fit the required starting conditions, those describing simpler, more harmonic motion like basic combinations of sin and cos usually result in a lower action integral. Increased complexity in the motion usually leads to a larger area. Among the non-pure harmonic functions tested, A*cos²(ωt) yielded the smallest action integral area which I got around 30 for. This is likely because its resulting motion for position and velocity remains relatively simple compared to the other trial functions. Overall, the exercise demonstrated how the choice of function influences the action and highlighted that simpler harmonic motions tend to minimize it. There is interest in exploring other functions that could potentially achieve an even lower value. |
Beta Was this translation helpful? Give feedback.
-
|
I experimented with several different functions that fit the initial conditions, including an exponential function and a few non-harmonic expressions, to see how they would impact the total action. While intuition suggests that simpler motions stay closer to the minimum, I was surprised to find that A*cos^2(wt) yielded one of the lowest areas, likely because its velocity and position curves remain relatively 'smooth' compared to the others. It’s been cool exercise in seeing how adding even small complexities to the motion starts to increase that action integral, confirming that the physical system really does prefer the most efficient path. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I experimented with different functions without changing the initial conditions, and found that the total action always go back a forth if iterate from a range of values. I did not choose to include any exponentials and found that the action always got higher from where ever I added more terms and values. I find it interesting that less complex is more efficient. Also, I found it interesting for using Julia for the first time since I usually use Matlab, love how linear algebra is very efficient like Fortran. |
Beta Was this translation helpful? Give feedback.
-
|
We know that the least action curve comes from solving the Euler-Lagrange differential equations for the action integral of kinetic minus potential energy. The differential equations simplify to trig functions representing oscillating curves. Knowing this, we can predict how the action integral will change in correspondence with manipulating the oscillation functions. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
When I introduced a slight perturbation to the true harmonic oscillator solution by adding a small extra term with something like x(t)=2cos(wt)+0.2sin^2(wt), it the motion still satisfied the same initial conditions x(0)=2 and v(0)=0, but its overall behavior changed noticeably. One trial function started at 2 with a smaller effective amplitude than the original cosine solution, while another variation began at 0 and resembled a reflected sine curve with much larger peaks reaching approximately + or - 20. Although these perturbed functions can look dramatically different, especially in amplitude, the key result is seen in the total action value which gave an output action of about −0.34 differing from the original solution’s value of -0.58. This demonstrates the principle of least action where even small deviations from the true cosine solution change the balance between kinetic and potential energy over time and change the integrated Lagrangian. The original harmonic oscillator solution is special because it minimizes or more precisely stabilizes the action and any small perturbation, even if it satisfies the same boundary conditions, results in a different total action, confirming that the original solution is the physically correct and natural most efficient path for the system. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I experimented with several trial functions using the same initial conditions from the harmonic oscillator to see how the total action changed when integrating the Lagrangian. Like others have observed, the functions that deviated more from harmonic motion tended to produce much larger action values. For example, I tested a few polynomial paths, and all of them gave noticeably higher action values compared to simple sinusoidal functions. The exponential version consistently produced one of the highest action integrals in my tests as well. Similar to what others found, the lowest action I obtained outside of sin/cos combinations came from a smooth, low‑complexity function—A·cos²(ωt). Its relatively gentle variation in position and velocity seems to help maintain a smaller integral overall. It was interesting to see how even small changes to the assumed trial path can shift the action quite a bit. |
Beta Was this translation helpful? Give feedback.
-
|
I tried a few different functions and also found that a combination of harmonic functions sine and cosine were the closest to least action which should be expected give the absence of damping from the equation of motion the general solution to this is X(t)=acos(wt) + bsin(wt) however the principle of least action gives a new prospective on why specifically there is only one solution when seemingly infinite solutions fit the initial conditions. |
Beta Was this translation helpful? Give feedback.
-
|
I tested different trial functions for the harmonic oscillator to see how they affect the total action. The principle of least action says the true motion makes the action stationary, so I compared different paths to the sinusoidal solution. When I used functions close to the true sine-wave motion, the action stayed relatively low. As I changed the function shape by adding distortions and changing the curvature, the total action increased. It shows that small deviations from the correct trajectory lead to a higher action value. |
Beta Was this translation helpful? Give feedback.
-
|
Using the Pluto.jl notebook I found that no matter what function was input, with the same initial conditions, the original function for v_an and x_an provided the smallest total action. Both when adding/removing different terms from the function the total action, while keeping the same initial conditions, the total action always increased. Plugging in various equations that others provided above also proved the same. Small deviations from the original equation will cause a larger action value. In dynamic systems we can infer that an equation with the smallest value of total action will be the most accurate representation of the equations of motion. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I tested a few different trial functions for the harmonic oscillator while keeping the same initial conditions and then compared their total action. I noticed that the analytical sinusoidal solution produced the smallest action and when I modified the waveform or added extra sine or cosine terms, the total action increased. My observations were similar to some of the other responses, especially how the functions deviating from the simple harmonic motion led to significantly larger action values. I also noticed how the closer the function was to sinusoidal form, then the smaller the total action would be. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I tried working through the notebook and playing around with the harmonic oscillator part, and I ran into something pretty similar. Even for a system that is “simple” like a harmonic oscillator, once you start modifying the trial functions, the behavior of the total action can change a lot more than you expect. When you plug the notebook from Pluto.jl using the file from 06_least-action.jl, the baseline solution that satisfies the boundary conditions gives the minimum action, which is exactly what you would expect from the principle of least action. But when you start trying your own functions, like adding small perturbations or using slightly different shapes between the endpoints, the total action always increases compared to that optimal path. What stood out to me is how sensitive the action is to those changes. Even small deviations from the true solution can noticeably increase the action, which really reinforces the idea that the physical trajectory is not just any solution, it is the one that minimizes the functional. It also makes it clear why numerical issues can show up. If your trial function or discretization is not well behaved, the computed action can jump around or give unstable results. |
Beta Was this translation helpful? Give feedback.
-
|
I used the Pluto notebook to test a few different functions for the harmonic oscillator while keeping the same initial conditions. No matter what function I tried, the original harmonic oscillator solution for x and v always gave the smallest total action. When I added extra terms or changed the shape of the function, the action value increased, even when the changes were small. Some functions stayed closer to the normal sin/cos motion and had lower action values, while functions that varied more from harmonic motion had much larger values. |
Beta Was this translation helpful? Give feedback.
-
|
For this exercise, I used the provided notebook to test several trial functions that satisfied the same initial conditions as the harmonic oscillator and compared their total action by numerically integrating the Lagrangian. Like many others found, the analytical harmonic oscillator solution consistently produced the smallest action. When I tested functions that deviated from simple harmonic motion such as exponentials, polynomials, or added high‑frequency “wiggles” the total action increased noticeably. This makes sense physically since added complexity increases velocity variations and therefore raises the kinetic energy term which accumulates in the action integral. Even small perturbations that visually look similar to the true solution still resulted in larger action values. One interesting result also seen by others was that smooth and low‑complexity alternatives like Acos2(ωt)A\cos^2(\omega t)Acos2(ωt) produced relatively small action compared to most non‑harmonic functions likely because the motion and velocity remain fairly smooth. Overall, this exercise made the principle of least action much more concrete by showing numerically that the physical trajectory is the one that the action is stable around while any deviation leads to a higher action. |
Beta Was this translation helpful? Give feedback.
-
|
It’s always a bit of a reality check when even the Professor runs into numerical instabilities, but it highlights how sensitive these solvers can be to the physics we’re modeling. For this exercise, I played around with a few different trial functions in the Pluto notebook to see how the total action (the integral of the Lagrangian over time) responded compared to the "true" path of a harmonic oscillator. I started by testing a simple linear path and a cubic function that satisfied the initial and final boundary conditions. As expected, these paths yielded significantly higher action values than the standard sine and cosine solutions. It really illustrates the Principle of Least Action in a tangible way—nature effectively "chooses" the path that minimizes this integral. When I strayed from the natural frequency of the system by injecting higher-frequency harmonic terms (like adding a sin(5wt) component), the kinetic energy terms spiked, causing the total action to climb rapidly. It’s a great visual reminder that any "unnecessary" motion or extra curvature in the path adds a penalty to the action. The most interesting part was seeing how small variations in the trial function could lead to vastly different results in the action calculation. I tried a damped harmonic expression just to see the effect, and while it stayed closer to the true path than the exponential function, the "cost" in terms of action was still notably higher than the undamped, natural oscillation. It’s fascinating to see that while many paths can technically connect point A to point B, the physics of the harmonic oscillator is perfectly tuned to find that one specific "path of least resistance" where the difference between kinetic and potential energy is optimized over time. |
Beta Was this translation helpful? Give feedback.
-
|
I tested doubling the frequency of the analytical solution. The true solution had a total action very close to 0, which is anticipated. When I doubled the frequency, the mass moved faster, so the total action went up to 379 because there is more kinetic energy. |
Beta Was this translation helpful? Give feedback.
-
|
I tried messing around with some different functions but didn't change the start and end points. I mainly noticed the action seemed to be smallest when the function closely resembled the normal harmonic oscillator motion. With functions that are more curved (exponential looking) the action increased. I think this is because those types of paths don't jive with the path the system wants to take. I also saw that small changes around the expected solution didn't change the action as much as I thought it would. This sort of made the least action idea click, since it's more about the real path being the closest to the most natural path compared to the other nearby ones. |
Beta Was this translation helpful? Give feedback.
-
|
I used the notebook to test damped trial functions and compare it to the actual oscillator solution. I expected to see that changing the motion would increase the action compared to the true solution. After running the calculations, the result showed the paths having a larger action than the oscillator. The added damping changed the shape of the motion over time and reduced the range of the oscillations. The motion remained smooth, but no longer had the same behavior as oscillator. The trials show how changing the motion affects the position and energy balance compared to the actual solution. |
Beta Was this translation helpful? Give feedback.
-
|
I tried testing a different trial function while keeping the same starting conditions, then compared the action value to the original harmonic oscillator solution. The numerical solution lined up really well with the analytical solution, which helped confirm that the ODE solver was giving the expected response for the equation x=−k/mx The position plot showed the normal sinusoidal motion, and the velocity followed the same harmonic pattern but shifted in phase. Looking at the energy plot also helped because the kinetic and potential energy kept exchanging over time. When displacement was largest, the potential energy was highest, and when the mass passed through equilibrium, the kinetic energy became highest. For the trial function part, I noticed that changing the function changed the action value, even when the initial conditions were still satisfied. The action was calculated from the Lagrangian, L=T−V so any change in the shape of x(t) and v(t) affected the total integral of the action. The value I got for the alternate function was close to the original, but not exactly the same. That made the least action concept make more sense to me because the real oscillator path is not just any path that works mathematically. It is the path that makes the action stationary compared to nearby possible paths. Overall, seeing the numerical solution, energy exchange, and action calculation together made the concept a lot easier to understand. |
Beta Was this translation helpful? Give feedback.
-
|
Similar to my peers, after testing the harmonic oscillator with the same initial conditions, the original harmonic oscillator solution for x and v produced the smallest total action. After adding extra terms or modifying the function shape, the total action increased. I observed that the functions that deviated from the simple harmonic motion led to larger action values. The total action would be smaller depending on how close the function was to the sinusoidal form. Changing the terms of the function shows us the relationship between change in motion and the position and energy balance in relation to the actual solution. |
Beta Was this translation helpful? Give feedback.














Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Numerical integration and principle of least action
I ended up recording x2 sessions for this topic because I ran into numerical instabilities for the brachistochrone differential equations. Sometimes its a nice reminder that no matter how long you've been using these tools, you can hit an error that you didn't expect.
Try your own functions for the harmonic oscillator solutions to see what changes in total action are here,
06_least-action.jl notebook
https://github.com/cooperrc/dynamics/blob/main/tutorials/06_least-action.jl
paste the link into your Pluto notebook and paste the describe the result here.
Beta Was this translation helpful? Give feedback.
All reactions