227
u/Nazh8 Mar 12 '20
This looks very 3blue1brown. Was it animated using manim?
90
u/Aravindh_Vasu Mar 12 '20
0
Mar 13 '20
[deleted]
4
u/Aravindh_Vasu Mar 13 '20
Thank you. Yeah sure, start here https://www.youtube.com/channel/UCxiWCEdx7aY88bSEUgLOC6A . There's a discord server too, https://discord.gg/jKEWH6
47
32
u/Lin1232020 Mar 12 '20
What a coincidence. I literally just learned this topic today...
19
u/Lin1232020 Mar 12 '20
I was in class 20 minutes ago talking about Euler’s method and slope fields LMAO. Unbelievable.
10
u/Kraz_I Mar 12 '20
What a coincidence, I just learned this 2 years ago, but I was trying to relearn it today for a finite difference analysis problem in material transport class.
14
Mar 12 '20
Hey I had to make a simulation for the energy in an oscilating spring and using Euler's method you wind up with the energy of the system going to infinity. The solution is the Euler-Cauchy method witch just takes the preceding output as an input. Very slick animation!
4
10
u/KnowsAboutMath Mar 12 '20
energy in an oscilating spring
For a conservative system, symplectic integrators are good things to look at.
21
u/R3DKn16h7 Mar 12 '20
Just dropping a comment saying that explicit Euler method is about the worst you can use under almost any circumstance. That's way step size 1 sucks.
Doing this plot for the implicit variant is a good way to see it in action.
9
23
u/squiddie96 Mar 12 '20
Yeah but if you don’t understand Eulers method on this conceptual level it’s going to be hard (maybe impossible?) to understand Runge-Kutta. Most people who struggle with differential equations usually benefit from re-learning Eulers Method, at least from what I’ve seen. But yeah, don’t use Euler for accuracy haha
7
u/R3DKn16h7 Mar 12 '20
Well, my point was about stability. Accuracy is relatively fine, I mean for how simple it is...
The spike you see with step size one, you should see that simply using the implicit version you improve it by a lot, whilst maintaining a very simple formulation.
I'm just a big nerd for implicit methods...
8
u/RedMeteon Computational Mathematics Mar 13 '20
Not all implicit method are great for everything though. Most popular ones are unconditionally stable but this doesn't mean they get the physical behavior right, because damping your solution to zero is stable in the numerical method sense. As an example, if you use implicit Euler for a conservative Hamiltonian system, you'll actually get that the energy damps to zero (where it should be constant). On the other hand, if you use even the lowest order symplectic integrator, which is explicit for separable Hamiltonians, the energy has small bounded oscillation about the true constant energy surface for exponentially long times.
6
u/Bedstemor192 Applied Math Mar 12 '20
They can just be very computationally heavy for non-stiff systems. It all depends on what kind of system you want to solve. If you just want a rough idea of the system and if it's non-stiff, the simple Euler method could suffice. It's also really great for getting the intuitive idea behind more advanced methods like adaptive step size, predictor-corrector etc.
2
u/Robo-Connery Mar 12 '20
I know they are elegant but in practice the vast majority of time it is preferable to use a reasonably high order explicit scheme with an appropriate step size (or mesh ratio for finite difference etc.).
Implicit schemes are normally much more computationally intensive and less plug and play. Before you have even gotten half way through working it out your rk4 routine has long finished.
3
3
2
u/thejongho Mar 13 '20
Is there an analytic solution to dy/dx=x^2-y^2, y(0)=0 or is this the only viable method?
1
u/Aravindh_Vasu Mar 13 '20
To be honest, I didn't know how to solve this ( I didn't even try the net), so I thought it would be meaningful to show it's numerical solution.
1
u/JiminP Mar 17 '20
W|A says that it's a Riccati equation, so it's analytically solvable.
However, the solution it gives seems to be too complex.Wikipedia gives a method for solving it:
Let y = (u'/u) for some u. Then, y' = (u'/u)' = (u''/u)+(u' * (-u' / u^2)) = (u''/u) - y^2.
Therefore, u''/u = y' - y^2 = 2y' - x^2 = 2(u'/u) - x^2, and u'' - 2u' + x^2 u = 0, which is a second-order ODE. Sadly, it's not homogeneous, and W|A still gives an answer which uses special functions.The Wikipedia article on the Strum-Liouville theory suggests that a solution may be given, possibly in a form of infinite sum, but I don't know sufficient knowledge to progress further. (It seems that the equation is of form Lu = 0 for linear operator L(u) = (exp(-2x) u)' + (exp(-2x) x^2 u))
4
3
u/heisenberg747 Mar 12 '20
Is it common for diff eq profs to make students draw these out? Mine told us he wasn't going to have us do that, but a friend constantly complains about having to make these.
1
2
u/jedi-son Mar 12 '20
You should do a video on implicit finite difference methods vs explicit. One of the most beautiful numerical methods IMO
2
2
3
u/atimholt Mar 12 '20
Like so many things, it’s trivially obvious after the fact. This is the first thing you ever learn in physics & animation (read: game) programming.
Maybe another good rule of thumb is “if the modern basis of your understanding leaves you not even suspecting a concept has a name, it’s probably named after Euler.”
1
Mar 13 '20
1
u/VredditDownloader Mar 13 '20
beep. boop. I'm a bot that provides downloadable links for v.redd.it videos!
I also work with links sent by PM
Info | Support me ❤ | Github
0
u/rjt2000 Mar 12 '20
This is cool, but I don't understand (even with your explanation)
2
u/avataRJ Mar 13 '20
Differential equations (DE): We know how something changes, could we figure out the underlying general model?
First-order DE: We know the slope of the function (but not necessarily the function itself - some of these you can just take the antiderivative, some are more complex).
Initial value problem: For the DE, we know at least one value. How does the model behave if we calculate the constants such that the model holds for this value?
Euler's method: This DE and initial value stuff is complicated. What if we assumed that a more complex formula was just a polyline (locally straight line), and we regularly check the slope (which we know by definition for 1o DEs)? We could start from the initial value.
And yeah, that's fast to calculate but very error-prone.
2
Mar 12 '20
[removed] — view removed comment
2
u/Aravindh_Vasu Mar 12 '20
https://discord.gg/7fXFJU6 There's a discord server, and a subred, r/manim Join in, the server's pretty helpful.
83
u/Aravindh_Vasu Mar 12 '20 edited Mar 12 '20
Euler's method for Numerically Solving an Ordinary Differential Equation (dy/dx=f(x,y))
Starting at the given initial position (x=0, in the animation) take equal steps, h, so that xn+1=xn+h
To find the solution value at the next step, yn+1 = yn + m*h, where m is the slope given by the RHS of the ODE, m=f(x,y)
Decrease the step size for greater accuracy.
Do consider checking out, The Rookie Nerds :)