Duffing | python code simulates the Duffing oscillator
kandi X-RAY | Duffing Summary
kandi X-RAY | Duffing Summary
This python code simulates the Duffing oscillator, a damped driven harmonic oscillator in a double well potential. It is a classic example of chaos theory, where the motion of the oscillator is strongly dependent on the initial conditions. The code should take less than 5 seconds to run as is, and outputs the Poincare map, which is a fractal. More details are found in duffing_oscillator.pdf.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- 2 function to 2
- Convenience function .
- Convenience function to calculate x and y
- Convenience function to equation 3 . 4 .
Duffing Key Features
Duffing Examples and Code Snippets
Community Discussions
Trending Discussions on Duffing
QUESTION
I was about to plot a Poincare section of the following DE, which is quite meaningful to have a periodic potential function V(x) = - cos(x) in this equation.
After calculating the solution using RK4 with time interval dt = 0.001, the one that python drew was as the following plot.
But according to the textbook(referred to 2E by J.M.T. Thompson and H.B. Stewart), the section would look like as
it has so much difference. For my personal opinion, since Poincare section does not appear as what writers draw, there must be some error in my code. However, I actually done for other forced oscillation DE, including Duffing's equation, and obtained the identical one as those in the textbook. So, I was wodering if there are some typos in the equation given by the textbook, or somewhere else. I posted my code, but might be quite messy to understand. So appreicate dealing with it.
...ANSWER
Answered 2021-Dec-10 at 09:57If you factor out some of the computation blocks, you can make the code more flexible and computations more direct. No need to reconstruct something if you can construct it in the first place. You want to catch the points where w0*t
is a multiple of 2*pi
, so just construct the time loops so you integrate in chunks of 2*pi/w0
and only remember the interesting points.
QUESTION
I have only been working with mex functions for a couple of weeks, and am now working on writing a Runge-Kutta, 4th order solver as a C++ mex function. I am wondering whether it is possible to take a function as an input. Effectively, it would be nice to have my dynamics function written in MATLAB and pass it straight through to my RK4 mex function. For example, if the dynamics are governed by Duffing's equation, written in MATLAB:
...ANSWER
Answered 2021-Feb-12 at 18:33Just quickly skimming the MATLAB C++ API doc, it looks like you can do this using the matlab::engine::MATLABEngine::feval interface found here:
I.e., pass your function name into the C++ mex file as a string which you can get from the ArgumentList via the matlab::data::CharArray syntax:
QUESTION
I try to solve the Duffing equation using odeint
:
ANSWER
Answered 2021-Jan-24 at 21:01Inserting the constants, the equation becomes
QUESTION
ANSWER
Answered 2020-Jul-06 at 20:46The main point to keep in mind is that you have to create 2D arrays of the velocities of the vectorfield U, V
by using the meshgrid np.mgrid
. Use the code below as a starting point and don't forget to play around with the options of streamplot.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Duffing
You can use Duffing like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page