Coding Challenge #93: Double Pendulum

  Рет қаралды 913,501

The Coding Train

The Coding Train

Күн бұрын

In this coding challenge, I create a double pendulum simulation in Processing. Code: thecodingtrain.com/challenges...
🕹️ p5.js Web Editor Sketch: editor.p5js.org/codingtrain/s...
🎥 Previous video: • Coding Challenge #92: ...
🎥 Next video: • Coding Challenge #94: ...
🎥 All videos: • Coding Challenges
References:
🔴 Physics Lab Double Pendulum: www.myphysicslab.com/pendulum...
Videos:
🚂 Pendulum Simulation: • 3.4: Pendulum Simulati...
🔴 Coding Train Live 120: • Live Stream #120: MNIS...
Related Coding Challenges:
🚂 #86 Cube Wave by Bees and Bombs: • Coding Challenge #86: ...
🚂 #159 Simple Pendulum Simulation: • Coding Challenge #159:...
Timestamps:
0:00:00 Double Pendulum Simulation
0:03:45 Creating The Double Pendulum
0:08:35 Adding The Tracing of The Path
0:12:51 Implementing The Double Pendulum Formulas
0:24:45 Visualizing It
0:28:21 Adding Damping
0:29:16 Conclusions And Suggestions
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
🚂 Website: thecodingtrain.com/
👾 Share Your Creation! thecodingtrain.com/guides/pas...
🚩 Suggest Topics: github.com/CodingTrain/Sugges...
💡 GitHub: github.com/CodingTrain
💬 Discord: thecodingtrain.com/discord
💖 Membership: kzbin.infojoin
🛒 Store: standard.tv/codingtrain
🖋️ Twitter: / thecodingtrain
📸 Instagram: / the.coding.train
🎥 Coding Challenges: • Coding Challenges
🎥 Intro to Programming: • Start learning here!
🔗 p5.js: p5js.org
🔗 p5.js Web Editor: editor.p5js.org/
🔗 Processing: processing.org
📄 Code of Conduct: github.com/CodingTrain/Code-o...
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
#doublependulum #pendulumharmonicmotion #processing

Пікірлер: 737
@sarath_sajan
@sarath_sajan 5 жыл бұрын
13:15 Note: the following proof is trivial and has been left as an exercise to the reader
@tooljockey2777
@tooljockey2777 4 жыл бұрын
lmfao love those videos
@jirobow
@jirobow 4 жыл бұрын
Physics books be like
@Commanderdata-po6ym
@Commanderdata-po6ym 4 жыл бұрын
Lagrange bra.
@quink3
@quink3 4 жыл бұрын
kzbin.info/www/bejne/qpSVkptjgNN3jtk in case you are interested ;)
@erickelley9888
@erickelley9888 4 жыл бұрын
@ bill bassichis
@RedTriangle53
@RedTriangle53 5 жыл бұрын
Fun fact in case nobody else has mentioned it: updating the positions using the "current velocity" vs the previous one changes the numerical method from Euler's method to the Euler-Cromer method, which is quite a lot more accurate. The regular Euler method is prone to inadvertently increasing the energy of the system, while the Euler-Cromer method conserves energy quite decently. The two methods seem almost identical, but the behind the scenes math is quite interesting and shows that they are actually of different orders.
@missingsemi
@missingsemi 6 жыл бұрын
“G is the universal gravitational constant, I assume. That’s just gonna be one.”
@nathanaelgodon1603
@nathanaelgodon1603 6 жыл бұрын
If only it became true at the moment he wrote it ! Some physics genius would have re-died. ^^
@aidenwatler7153
@aidenwatler7153 6 жыл бұрын
Missing Semicolon I died. Small g is acceleration of gravity on earth = 9.81 m/s^2. Big G is the universal gravitational constant, 6.67 x 10^-11. TRIGGERED!!!
@up4life108
@up4life108 6 жыл бұрын
Most of the time you don't use actual real values in code because in order to have them work properly ud have to do a lot more work.
@PatMende
@PatMende 6 жыл бұрын
ħ = c = G = 1
@eddyrose3254
@eddyrose3254 6 жыл бұрын
This was golden hahahah thank you so much for this
@Phi1618033
@Phi1618033 4 жыл бұрын
"Okay, I'm gonna see if I can just copy and paste this enormous differential equation right into my code."
@AdityaFingerstyle
@AdityaFingerstyle 6 жыл бұрын
To those who want to make this simulation more real do this. Currently Dan is setting g = 1. Although its far from the actual value the simulation looks very real. This is because one second in the simulation is one frame. And by default processing or p5.js is set to 60 fps. This means when one second passes in real world, 60 seconds would have passed in the simulation world. Hence the correct value of g would be 9.8/ ( 60 * 60 ) . There's still one more thing to adjust. The masses are actually in kilograms hence you should set the value of bob masses to around 0.05 which is 50 grams. Also, the lengths are in meters so make that they aren't very large.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thanks for these comments!
@SRAVANAM_KEERTHANAM_SMARANAM
@SRAVANAM_KEERTHANAM_SMARANAM 4 жыл бұрын
This Guy has made a magic. But when we give the real numbers within no time, the software is getting into errors. he has very intelligently demonstrated the capabilities given the limitation of a 30 min video. The world appreciated him for this.
@YouReyKarr
@YouReyKarr 3 жыл бұрын
Nope
@sethmobit
@sethmobit Жыл бұрын
I changed and now it's really really slow
@joaovitordasilvabonadiman8303
@joaovitordasilvabonadiman8303 6 жыл бұрын
OMG, I've watched a 30 min video without even noticing it. Thanks for existing, Dan!
@nicerholunder9414
@nicerholunder9414 5 жыл бұрын
João Vitor Bonadiman Same... When I noticed the video would end soon from the way he talked I looked up the runtime because I hoped there was more to come with messing with the values. Then I noticed I've watched 30 min of coding feeling like 5...
@photon2724
@photon2724 5 жыл бұрын
i have no idea wats going on. yet im enjoying this video.
@softpaw6234
@softpaw6234 3 жыл бұрын
Story of my life online
@kaledbrahmi3442
@kaledbrahmi3442 3 жыл бұрын
Same
@wolfevan5880
@wolfevan5880 2 жыл бұрын
Same
@technicallokaya6726
@technicallokaya6726 2 жыл бұрын
Like 2 livers connected and if we swing it from the free end, it creates a beautiful art. I guess that's what he did. Not sure.
@thedarkknightclipss
@thedarkknightclipss 2 жыл бұрын
😂😂😂 Me too
@lepetrolophiledu6221
@lepetrolophiledu6221 6 жыл бұрын
I really REALLY laughed when the pendulum just started warping into another dimension at 12:30 *"See, this is kind of the idea"*
@purnya2
@purnya2 6 жыл бұрын
you just made my day hahahaha
@otesunki
@otesunki 5 жыл бұрын
Hahahaha
@_news_of_the_world_
@_news_of_the_world_ 5 жыл бұрын
He just made the flower of life
@Miaumi
@Miaumi 5 жыл бұрын
Was my thought too :D
@TheUltimateVanquish
@TheUltimateVanquish 6 жыл бұрын
I think a cool feature to add would be a fade of the trace line, so as a segment of line is drawn, say 5 seconds later it begins to fade, so you only ever have the last 5 or so seconds of trace at any given time
@bard-anilsen
@bard-anilsen 4 жыл бұрын
Something like this in draw: fill(255,10); rect(0,0,width,height);
@matthimf
@matthimf 4 жыл бұрын
24:10 you are changing the integration method from simple explicit Euler to symplectic Euler which is numerically much more stable.
@rboyce1000
@rboyce1000 4 жыл бұрын
Top comment!! This explains your astute observation at 23:33 "It's got quite a bounce to it." The simple/forward Euler method tends to artificially add energy to this system, while the symplectic/semi-implicit Euler method is better at conserving energy. There are many other variant methods, including the so-called midpoint method (angle is updated by the average of present and future velocity steps).
@Chandrashekar-fd1dg
@Chandrashekar-fd1dg 3 жыл бұрын
W h a t
@prerit714
@prerit714 Жыл бұрын
I found some math gods here...
@ayjaygame
@ayjaygame 6 жыл бұрын
I never knew i could be so engaged and laugh at someone doing something like this. Great video! :)
@cashel1111
@cashel1111 6 жыл бұрын
this is the first of your videos i have seen, i am so glad people actally go through these sort of things for others to see keep up the good work :)
@nathannolte4333
@nathannolte4333 4 жыл бұрын
17:49 "Oh I forgot a semi colon" Me: (Laughs in Python)
@killereks
@killereks 4 жыл бұрын
Imagine running your programs at 60 fps Me: laughs in c++
@thewild2334
@thewild2334 4 жыл бұрын
@@killereks imagine not having Dynamic Memory Allocation Me: also laughs in python
@killereks
@killereks 4 жыл бұрын
@@thewild2334 imagine spending too much memory on a slow list. Me: laughs in C
@cloudyshows3674
@cloudyshows3674 4 жыл бұрын
@@killereks Imagine running your program in the browser. Me: laughs in JavaScript
@tathagatmaheshwari6685
@tathagatmaheshwari6685 4 жыл бұрын
why did you guys stop??
@DowzerWTP72
@DowzerWTP72 6 жыл бұрын
I'm so happy you've done this; I started making one of these in P5 using a class, and I just figured you'd use basic Trig to calculate the angles. Had literally no idea the lre was a huge algorithm derived for it! Gonna give this a looking soon!
@MicheleMerlino-yb3og
@MicheleMerlino-yb3og Жыл бұрын
We need more teachers like you, I'm starting to enjoy coding thanks to you!
@TheDyingPlant
@TheDyingPlant 2 жыл бұрын
You’re one of those special people in the world that make it a better place. You can always tell, and it just radiates from you.
@tryphonunzouave8384
@tryphonunzouave8384 5 жыл бұрын
Idk why this was recommenced to me, I never even coded, but you're so full of energy and entertaining, thumbs up dude
@JeffBezosOfficial
@JeffBezosOfficial 4 жыл бұрын
First video I watch from this genius. You’re funny as hell, your channel’s gonna get me hooked. Thanks.
@taylorjeffery4145
@taylorjeffery4145 4 жыл бұрын
"I'm not going to derive those formulas" *cries in physics major
@termitori
@termitori 4 жыл бұрын
@Max Beer more easy to use Hamiltonian
@mr.mirror1213
@mr.mirror1213 4 жыл бұрын
@@termitori Hamiltonian is advanced Lagrange
@JoeyFaller
@JoeyFaller 4 жыл бұрын
@@mr.mirror1213 but it makes it so easy. the hamiltonian destroys everything you thought you knew about classical mechanics and it's fucking beautiful
@ratulbanerjee8456
@ratulbanerjee8456 4 жыл бұрын
Exactly man, after using lagrangian it bacame easior
@anujmithbavkar9933
@anujmithbavkar9933 5 жыл бұрын
It's so satisfying to see the joy on his face as if he became a father😄great man to be convinced to get into coding
@talkingtornedo3054
@talkingtornedo3054 6 жыл бұрын
you are a blessing !!!! a true blessing. I cant thank you enough for what you are doing.
@blutstein1210
@blutstein1210 6 жыл бұрын
The first time i see, why i had to learn all the Math in school xD
@MonsterhunterFTWWTF
@MonsterhunterFTWWTF 4 жыл бұрын
All those physics courses really made me understand this, I'd be lost without taking those courses tbh.
@hmd5298
@hmd5298 5 жыл бұрын
This is the best KZbin channel I've ever seen
@klivecorps
@klivecorps 2 жыл бұрын
THIS IS A PERFECT EXAMPLE OF HOW TO DO AND HANDLE COMPLEX PROJECTS AND COMPLEX ALGORITHM. YOU'RE GREAT!!
@ethanhermsey
@ethanhermsey 6 жыл бұрын
awesome :D i always get so excited when i see a new video on this channel. I even managed to attend some live streams. I love how weird you are :D and how you can explain these pretty complicated concepts in a way that is so easy to understand. I've tried the same with the matter.js library but failed miserably :p nicely done!
@toastrecon
@toastrecon 5 жыл бұрын
Pretty cool! A few things: the dampening should be a function of velocity, proportional using some constant. It would be harder/maybe fun to calculate the forces along the bars and have them extend elastically under the load.
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
thanks for this feedback!
@victoralvesbugueno6178
@victoralvesbugueno6178 6 жыл бұрын
Make a pendulum wave, multiple pendulums with differents arm length, that effect is pretty awesome !!
@ChaoteLab
@ChaoteLab 6 жыл бұрын
Go Dan! GO!
@CanadianMang
@CanadianMang 5 жыл бұрын
Dude you are a gifted individual.
@user-zb8tq5pr4x
@user-zb8tq5pr4x 4 жыл бұрын
You should try to create a simulation with vectors as well, it would be interesting. (Calculate the motions without formulas, just using vectors and addition)
@CedricRBR
@CedricRBR 6 жыл бұрын
Quick wallpaper I did using this: i.imgur.com/BSb37so.png
@ayeyefookinw0tm859
@ayeyefookinw0tm859 6 жыл бұрын
Cédric Reber nice wallpaper
@TheTanmaybishnoi
@TheTanmaybishnoi 6 жыл бұрын
Too Good
@ricardosallin1670
@ricardosallin1670 4 жыл бұрын
You are the one Level 99 developer that I've spent my entire life looking for. If there was a 10th Dan for programmers, it'd be yours. Thanks for existing.
@ian-evanmichel8185
@ian-evanmichel8185 6 жыл бұрын
And by the way, if you or anyone else want to solve the problem at the end ( I mean that the pendulum is getting higher and higher and even faster) you need to use another way to solve numerically the differential equations. Here you used the Euler method (explicit) ( v += a and x+=v). There is a loose of accuracy because of the integration step. In order to fix it (or to make it better) you can use the RK4-method (Runge Kutta 4) which will make you gain in accuracy without reducing the integration step of time (which is expensive in terms of calculation time). I know it's a bit more complicated but it's worth it ( I personally have tested it with pendulums and with gravity simulation with planets and orbits which can degenerate).
@LuisHerrera-gi8wu
@LuisHerrera-gi8wu 6 жыл бұрын
You do great videos, congrats!!!
@JW-pq1ml
@JW-pq1ml 5 жыл бұрын
I just found my new favorite channel.
@aradarbel4579
@aradarbel4579 6 жыл бұрын
that is VERY hard to create a double pendulum, just because it's so random and hard! I didn't watched the video yet, because as always; I'm first trying the challenge myself and then trying your code. This one was IMPOSSIBLE!! good job Dan!!!
@johanrojassoderman5590
@johanrojassoderman5590 4 жыл бұрын
"I'm right about the angular acceleration, because it's going in a perfect circle" - Dan 2018
@ssbmwine9387
@ssbmwine9387 6 жыл бұрын
There is a small error here in the equations of motion. Because the canvas draws the origin in the top left, the derivation used here is slightly wrong. This is accounted for in drawing the pendulum. However the error propagates into the angular acceleration equation. There are two ways to fix this: 1) Fix the equations of motion by doing a coordinate transformation of the solution g -> -g, and cos(angle1) and cos(angle2) also go to negatives. This is actually a bit harder than it looks because there are a lot of trig identities you'd need to pull out to di this. 2) Fix the coordinate system When I implemented this myself using plain old JavaScript the Canvas Context object allows you to scale it by a negative number. Then fix how you draw the pendulums so y = -cos(angle) * length. I believe a way to accomplish this in Processing would be the rotateX() function.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thank you for this feedback!
@maxxoumaxime
@maxxoumaxime 5 жыл бұрын
hey, I've encountered the exact same problem you pointed out, could you help me with it in more detail ? I'm kinda lost. For g--> - g, easy to understand but what do I do for the trig identities ? Thanks
@heliumhydride
@heliumhydride 4 жыл бұрын
Absolutely love you videos. I also found out that if you try to compute the total energy of the system, it is NOT conserved, I wonder what is wrong, everything seems to work fine except that
@kajhall3581
@kajhall3581 4 жыл бұрын
This was my second year BSc Physics coding project (circa 2016). It was hardcore, but definitly do-able :D
@masterflamaster6377
@masterflamaster6377 6 жыл бұрын
Wow, Dan! I didn't know you are so good at object oriented programming!
@mkelly568
@mkelly568 5 жыл бұрын
i've literally never watched a coding video before (but i've at least taken calc and physics haha) but somehow this made sense, so props to you as a teacher!
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
Glad to hear! You can use either of these playlists to start from the beginning! kzbin.infoplaylists?view=50&shelf_id=14&sort=dd kzbin.infoplaylists?view=50&shelf_id=2&sort=dd
@yahia1355
@yahia1355 3 жыл бұрын
man , watching this smart and fun guy is another level of happiness :D !
@nietschecrossout550
@nietschecrossout550 6 жыл бұрын
15:00 you hurt the physicist in me so darn hard XD
@ObjectsInMotion
@ObjectsInMotion 5 жыл бұрын
René Carannante Actually, that's exactly what a physicist would have done. We set constants to 1 all the time. Like in relativity, c is always 1
@pati7132
@pati7132 5 жыл бұрын
First of all, c is simply the speed of light, it is NOT 1. In special relativity we treat it as 1 because that's the the ratio speed of light/speed of light = 1 , and other speeds are written in terms of c so it's easier to do lorentz transformations. Physicists don't set constants. Ever. You can't just set a constant to whatever you want.
@ObjectsInMotion
@ObjectsInMotion 5 жыл бұрын
Pati, clearly you aren't a physicist. There is nothing fundamental about the meter or the second that makes them absolute in any way. All dimensional constants are dependent entirely on the measuring system you use them with. Who sets the measuring system? Physicists. You CAN set the speed of light to whatever you want, just by using whatever length you want. It's not just a notational trick, the speed of light IS one lightyear per year, or one lightsecond per second, etc. The only FUNDAMENTAL constants are the dimensionless ones, like the fine structure constant or the strong coupling constant, dimensional constants like the speed of light and gravitational constants are all secondary.
@MrJerryHsu
@MrJerryHsu 5 жыл бұрын
Pati I think you must understand that anything can be referenced in relation to everything, regarding certain vectors of location and assuming small scale locality and infinite spatial dimensions of said locality. Therefore, symbology and meaning in this world is manifested solely based on our reality and thought processes from the point of which we stand. There’s a reason why everyone else besides the US uses the metric system. Because it’s easier to work with. Why would you want to make things harder for yourself?
@sujals7108
@sujals7108 5 жыл бұрын
@@pati7132 I agree
@Morszczux
@Morszczux 6 жыл бұрын
Now me as a physics student want to make 3D version where all of the formulas are calculated by me! Funny thing is that last semester I had classes called Classical Mechanics and one of the tasks on final exam was to calculate this formulas in double pendulum ;>
@up4life108
@up4life108 6 жыл бұрын
Sounds hella fun. Would love to see a 3d version!
@mr.fluffypantz4150
@mr.fluffypantz4150 6 жыл бұрын
Morszczux Lagrangians save lives
@Morszczux
@Morszczux 6 жыл бұрын
Mr. Fluffypantz True!
@DaviAyres
@DaviAyres 5 жыл бұрын
This was awesome. Thanks!
@DarkRedman31
@DarkRedman31 5 жыл бұрын
29:03 actually you don't need that dampening since you have in the g value, since it's 1 it won't really change the result of the formula but if you tweak it to be 9,807 m/s² (earth gravity) it'd change, I like moon, mars and sun values to play with.
@m.sierra5258
@m.sierra5258 6 жыл бұрын
Hey! I'd love to see you implement the '4th order runge kutta' method for that. What you did (v+=a; x+=v) is called 'Forward Euler Integration', 'Runge Kutta Integration' is basically the same, but with multiple intermediate steps. That achieves an accuracy that goes down two more taylor iterations, removing the 'energy gain' over time.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Yes, it would be nice to cover this sometime!
@khernandezpardo
@khernandezpardo 6 жыл бұрын
I did that here for multiple pendula: github.com/kevinhp/multiplePendula
@danielheinrich869
@danielheinrich869 6 жыл бұрын
See here for a working implementation: www.openprocessing.org/sketch/507468 Cheers, Daniel
@celiacasimiro465
@celiacasimiro465 4 жыл бұрын
22:50 The most beautiful sound you can hear...
@yovhal1980
@yovhal1980 3 жыл бұрын
I go to know so many things related to coding bcuz of you thanks a lot for making such amazing tutorials. Now I can kinda convert Java into Javascript(as thats the only language I know). They are so fun to follow along!!!
@ricard458
@ricard458 Жыл бұрын
Amazing... Chaos moviment.. and the butterfly effect. You are great!
@lukasaudir8
@lukasaudir8 5 жыл бұрын
that was awesome man!!
@sulfursw9286
@sulfursw9286 5 жыл бұрын
It was interesting, thank you)
@binarysaiyan9389
@binarysaiyan9389 4 жыл бұрын
You are simply awesome!!!
@ujjwaladitya1042
@ujjwaladitya1042 3 жыл бұрын
You are surely the best coding tutor available
@AdityaPutatunda
@AdityaPutatunda 4 жыл бұрын
You can check your code by making both angles kept equal throughout and starting out with a small angle such that it recreates a rigid rotor case.
@ahzazz
@ahzazz 6 жыл бұрын
Thanks for introducing me to Processing....
@Crazy1793
@Crazy1793 5 жыл бұрын
25 mins in and I'm subbing. You're awesome. If you need help with understanding these equations I would be happy to help out. I'm an currently a master engineering student in the Netherlands. And I know python language coding
@josebreijo3850
@josebreijo3850 6 жыл бұрын
So much fun watching this
@good_brake
@good_brake 6 жыл бұрын
The reason that updating the velocities and then the positions works better is because it's a symplectic forward Euler integration scheme which more closely captures the symplectic geometric structure of the (Hamiltonian) double pendulum system, and so you get less numerical integration error. You can also write down the general equations of motion for a generalized pendulum fairly easily in the case where the lengths and masses of the pendulums are the same, and I'm sure it's just a tedious generalization to consider distinct masses and lengths.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thanks for this information!
@5_inchc594
@5_inchc594 4 жыл бұрын
For those who does not understand why at 24:30, switching the velocity before position fixed the problem, here is the technical explanation: it seems like its the same, but if you work out the math, position first is called Euler's method whose error is not bounded. As time goes by, the error will be big enough(if you plot the energy of the system, it continuously goes up) , it seems like it getting more energetic. If you put the velocity before the position, the error is bounded. He accidentally used a method called Verlet method whose error is bounded in this case. therefore, as time goes by, the energy of the system fluctuate within in a range, therefore, it looks real.
@xetop
@xetop 6 жыл бұрын
Great Video, thanks for sharing.
@ronaldjensen2948
@ronaldjensen2948 4 жыл бұрын
Rather than calculate the angles, I calculated the force in the connecting rods and used a pair of standard movers, with the child pendulum applying its rod force to the parent pendulum. Seems to work fairly well. I also call canvas.background() with a very transparent color so the trace fades over time.
@taylorjeffery4145
@taylorjeffery4145 4 жыл бұрын
The double pendulum is a system of four first order non-linear differential equations. A better method of approximating the solution would be an ODE solving algorithm like Runge-Kutta. Simply adding acceleration to velocity and velocity to position will only be valid for a very short time interval after release due compounding error.
@marco.nascimento
@marco.nascimento 6 жыл бұрын
wow, that's pretty awesome.
@profemanoelsilva
@profemanoelsilva 5 жыл бұрын
Cara, muito pai dégua teu trabalho!
@marcioamaral7511
@marcioamaral7511 5 жыл бұрын
Professor de Física Ele aceitou na programação mas errou na física
@purifierphoenixthemecca2074
@purifierphoenixthemecca2074 6 жыл бұрын
Next challenge Gravitational Waves
@ayeyefookinw0tm859
@ayeyefookinw0tm859 6 жыл бұрын
Purifier Phoenix The Mecca hell yeah
@jujhaarsingh7889
@jujhaarsingh7889 5 жыл бұрын
g is acceleration due to gravity G is the universal gravitational constant
@kenzarezyarifin1076
@kenzarezyarifin1076 3 жыл бұрын
That probably the craziest formula I've ever seen
@magneticking4339
@magneticking4339 3 жыл бұрын
7:36 You could delete that second fill function call just before the ellipse function call you are in this moment, sine the you are just resetting it to the same value. Indeed, the program also works if you move the fill function call to setup()
@americanmcgeesalicefanatic8904
@americanmcgeesalicefanatic8904 5 жыл бұрын
I know absolutely nothing about coding and all of this is foreign to me but I love watching you lol
@vfnikster
@vfnikster 4 жыл бұрын
You're using the 1st order Euler method to solve the differential equations, it is very rough and you get the increasing total energy to your system with time. Check please the sum of kinetic and potential energy of the pendulum. To fix the problem you should damp the velocity in such a way that the energy is kept constant.
@rickyrockbassist
@rickyrockbassist 5 жыл бұрын
95/5000 it will not be the same pattern, the inverted pendulum is a non-linear and chaotic system ... great work
@NonTwinBrothers
@NonTwinBrothers 6 жыл бұрын
haha, double pendulums are great
@Bunglay
@Bunglay 6 жыл бұрын
lol
@graysonmullins3167
@graysonmullins3167 2 жыл бұрын
This code helped me make a spirograph generator.
@atrumluminarium
@atrumluminarium 6 жыл бұрын
In the limit as _r2_ , _m2_ → 0 and _r1_ , _m1_ get large the behaviour should in theory also start to approach that of a single pendulum
@Prosege_Lumpascoodle
@Prosege_Lumpascoodle 6 жыл бұрын
Dan, i would like to challenge you to recreate this but in 3D. Still a double pendulum but can rotate along a z axis aswell. Think this would make a cool project, since it seems like a very difficult thing to recreate in the real world.
@krzysztofbandyk168
@krzysztofbandyk168 6 жыл бұрын
Two strings Two masses and a conection to the celling. but a simulation would be cool either way.
@yjr4df758
@yjr4df758 3 жыл бұрын
It could be a good beginner project, specifically for people learning to deal with neural networks, to train a neural network to predict a double pendulum.
@HerrKichern
@HerrKichern 4 жыл бұрын
Update the velocity before the position, it is a more stable integration method (semi-implicit euler integration)
@danielw.4876
@danielw.4876 4 ай бұрын
One tiny thing I would change is making the width and height of the masses proportional to the square root of the mass, that way the area is proportional to the mass.
@AbhishekSachans
@AbhishekSachans 5 жыл бұрын
BTW, those 'crazy' expressions of accelerations can be derived using euler-langrange equation (a part of langrangian mechanics). Infact, It's very simple, not crazy at all :)
@phrostbit3n
@phrostbit3n 4 жыл бұрын
"Somebody crazy calculated it" Yes, intro phys students are absolutely insane
@zsigmondforianszabo4698
@zsigmondforianszabo4698 3 жыл бұрын
12:43 hmm that pendulum looks like a famous logo... that's a new brand I believe?
@harshitmalhotra8627
@harshitmalhotra8627 5 жыл бұрын
Loved it
@erslippers3805
@erslippers3805 4 жыл бұрын
Interesting fact: the 2 angles form a diagonal Lissajous curve (sort of)
@bigchicharito4813
@bigchicharito4813 4 жыл бұрын
Hi , I have a doubt. Without getting the function called , how is there constant incrementing and decrementing in the first third of the video?
@carlesmanguiano
@carlesmanguiano 4 жыл бұрын
For those interested, formula comes from approximating Runge Kutta numerical solution. You might as well program it so you do not have the need to write the "analytical" solution.
@monky123344
@monky123344 4 жыл бұрын
The way to calculate the double pendulum is actually not incredibly complex. There's really 2 main things you have to know. 1.) you have to know the physics in order to get a formula for the kinetic and potential energy for each of the masses. 2.) you have to know the Euler-Lagrange equation. you use the formulas for the kinetic and potential energy to get two differential equations, and really the complicated part is the algebra for actually solving for the angular acceleration for theta1 and theta2 because the equations is a little long and both accelerations show up in both equations. The original differential equation is (relatively) simpler and not too complex to see where each part of the equation comes from.
@destinyjames6117
@destinyjames6117 3 жыл бұрын
The pendulum going crazy is my favoirite part
@smartphonesammler3924
@smartphonesammler3924 3 жыл бұрын
Not bad, but there has to be a more general formula for it. Because what do you do if you want a triple or quadruple pendulum now? You can't always come up with a new formula, physics is based on general formulas and there is not a separate formula for every possible event.
@Invalid571
@Invalid571 5 жыл бұрын
A detailed explanation on how to derive the equations of motion for the double pendulums: kzbin.info/www/bejne/pJbLaWmrbMSHf80
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
Thanks for this reference!
@mynameisnobody1fjb372
@mynameisnobody1fjb372 6 жыл бұрын
Any idea why the translate function is not translating to the coordinate (300, 50)? It draws the tracing points at the origin (0, 0). I tried with the translate func at different places, no effect. I am at 12:40
@charbelsarkis3567
@charbelsarkis3567 6 жыл бұрын
You should make videos on Changing values and seeing what happens. :P
@zaheeruddinfaiz7064
@zaheeruddinfaiz7064 4 жыл бұрын
Hi, this is a great video! Could you please tell me the environment you have for coding. Like language and libraries, etc. ?
@TheCodingTrain
@TheCodingTrain 4 жыл бұрын
This video uses Processing (which is built on top of the Java programming language). For more info, visit processing.org and also this video might help kzbin.info/www/bejne/d57PcpyBqM6sZtE.
@rashedulislam9301
@rashedulislam9301 4 жыл бұрын
You are really awesome man.
@federicopanichi9874
@federicopanichi9874 4 жыл бұрын
One question, what video editor do you use to overlap you so smoothly to your screen? Thx
@Victor-em1ms
@Victor-em1ms 6 жыл бұрын
What is the font that you use to get those 'i' and 'l'? I like it a lot.
@sankamohottala6778
@sankamohottala6778 5 жыл бұрын
use{{ a1_v+=a1_a*t; a2_v+=a2_a*t; a1+=a1_v*t; a2+=a2_v*t;}} this way you can change the defined 't' to any number.because in this code the maths part becomes more and more inaccurate or as the time goes.(i.e as more x,y pairs get drawn on canvas).because the whole mathamatical process in your code is approximated integration but you assume the delta t is 1. By changing the delta t(in my code it's t as you can see ) the integration becomes more accurate.also put 10 for g.
@charlie3k
@charlie3k 6 жыл бұрын
Just, wow.
@WaltherSolis
@WaltherSolis 6 жыл бұрын
The second angle for the formula is positive going clockwise but you did It positive counterclockwise
Coding Challenge #94: 2048 - Part 1
35:17
The Coding Train
Рет қаралды 146 М.
Coding Challenge #144: 2D Black Hole Visualization
42:30
The Coding Train
Рет қаралды 229 М.
КАРМАНЧИК 2 СЕЗОН 5 СЕРИЯ
27:21
Inter Production
Рет қаралды 499 М.
OMG 😨 Era o tênis dela 🤬
00:19
Polar em português
Рет қаралды 8 МЛН
Coding Challenge 168: MandelBulb 3D Fractal
28:02
The Coding Train
Рет қаралды 364 М.
Is it Possible to Predict Randomness? The Double Pendulum Experiment
6:41
Double pendulum: equations of motion for small oscillations
22:48
Dr Ben Yelverton
Рет қаралды 15 М.
Coding Challenge 180: Falling Sand
23:00
The Coding Train
Рет қаралды 724 М.
Coding the Collatz Conjecture
23:08
The Coding Train
Рет қаралды 128 М.
I'm Coding an Entire Physics Engine from Scratch
9:19
Gonkee
Рет қаралды 1,6 МЛН
The Double Pendulum in PYTHON
23:03
Mr. P Solver
Рет қаралды 29 М.
Coding Challenge #143: Quicksort Visualization
30:06
The Coding Train
Рет қаралды 244 М.
Coding Challenge #113: 4D Hypercube (aka "Tesseract")
43:53
The Coding Train
Рет қаралды 250 М.
Coding the Hilbert Curve
28:08
The Coding Train
Рет қаралды 108 М.
КАРМАНЧИК 2 СЕЗОН 5 СЕРИЯ
27:21
Inter Production
Рет қаралды 499 М.