2d motion simulator for given differential equations - simulation

Phet has a really neat simulation here for gravitation orbits that you can play around with. Are there any other simulations out there that let you do the same, but also allow you to play around with the equations of motion? (ie. diff equations). I think it would make for great learning tool to see how gravity would function if instead of being a 1/r^2 force, it was 1/r or r or sqrt(r), etc...
Thanks.

Mathematical tools like matlab (alternatively scilab or octave) or mathematica (alternatively sage or wxmaxima) propose ODE solving stuff / integration tools, I guess you can have a look at them. You can use them to integrate your equations then plot them and deduce the different behaviours. This will always be "less graphical" though.
The MIT youtube channel has a course about Differential Equations, with some videos about matlab tools, you can have a look at them here

Related

Which C++ library is perfect in solving non-linear set of equations with complex roots?

I am developing a small kinetic Monte Carlo code to study atomic evolutions in a material and need to solve several linear and non-linear equations with a high accuracy. My main issue is in finding complex roots of a non-linear equation.
Which C++ library is perfect for solving a non-linear set of equations with complex roots? I am already using Eigen and Ceres in my codes, but it seems that they only can find "real" roots and not "complex" ones.
All recommendations and ideas are appreciated in advance.
Update-1:
For example, Eigen provides a nonlinear optimization module,
https://eigen.tuxfamily.org/dox/unsupported/group__NonLinearOptimization__Module.html
which uses (1)Levenberg Marquardt algorithm and (2)Powell hybrid "dogleg" method to find roots and extremums of a nonlinear set of equations. As far as I know, these methods can't find complex roots if any.

Can Simscape Multibody or Simscape Driveline generate automatically the dynamic equations of motion?

The description of the Simulink MATLAB package for Simscape Multibody says it can formulate the equations of motion for a mechanical system. I searched everywhere in the documentation and examples and I can't find a single example of how to do this, is there a specific block or does it actually mean the software calculates the equations as a black box and can't be extracted? Additionally, I'm also looking to calculate and simulate the natural frequencies of a planetary gearbox, can this packages also do this?
I'd appreciate any comments and suggestions, thank you!
https://uk.mathworks.com/help/physmod/sm/
"You can model multibody systems using blocks representing bodies, joints, constraints, force elements, and sensors. Simscape Multibody formulates and solves the equations of motion for the complete mechanical system. You can import complete CAD assemblies, including all masses, inertias, joints, constraints, and 3D geometry, into your model. An automatically generated 3D animation lets you visualize the system dynamics."
Simscape Multibody solves the equations of motions under the hood, it does not make them available to the user. It is in effect, a black box.
With regards to vibration analysis, this can be done in the Simscape Driveline package. Though the level of detail might not be high enough to do this for a single planetary gearbox.
There's a tool called simscape2casadi that, though in alpha stage, claims to be able to do what you want. A description can be found in this paper and the code can be found in this git repository. Please note that it requires Simulink Coder to generate C code from your model.

Modelling dynamical systems with MATLAB/Mathematica

Recently I have been performing simulations on some dynamical system, where all the dynamical quantities are interdependent. To therefore simulate the dynamics I performed loops over small time steps dt<<1 and changed the quantities within each iteration. The simulations were done in respectively Mathematica and Matlab.
I got nice results but simulations could take quite long due to the slow iteration process. Generally I hear that one should avoid for loops like I have used, because they slow down the simulation greatly. On the other hand however I am clueless on how to do the simulations without iterations in small time steps. Therefore I ask you: For a dynamical system, where every quantity must be changed in ultra small time steps, what are then the possible methods for for simulating the dynamics.
The straightforward approach is to write the problem as a set of differential equations and use the ODE solving capabilities of either system. Both MATLAB and Mathematica have advanced (and customizable) numerical differential equation solvers, and they both support special "events" in the differential equations that can't be expressed using a simple formula (e.g. the event of a ball bouncing back from the floor).
For Mathematica, first check out NDSolve, WhenEvent then later the Advanced Numerical Differential Equation Solving tutorial.
From your description it sounds like you may be using a naive ODE solving method such as the Euler method. Using a better numerical ODE solving technique can give significant effective speedups (by not forcing you to use "ultra small time steps").
If performance is paramount, consider re-implementing the simulation in a low-level language like C or C++, and possibly making it callable from Mathematica (LibraryLink) to allow easy data analysis and visualization.

Using a non-matlab ODE simulator to run a model created in matlab/simbiology - how to represent "repeated assignment" rules?

I am using non-matlab ODE simulation software to reproduce a model that was created with the simbiology toolbox in matlab.
One issue is the representation of repeated assignments. Is it possible to re-express repeated assignments in a way that they can be simulated in a standard Runge Kutta (or other iterative method) which only supports ODE systems? Or is it impossible re-express a model with repeated assignments as a system of ODEs?
It is possible. In SimBiology, for most repeated assignments, you can take the assignment statement
x = y + z
and think of it as
dx/dt = dy/dt + dz/dt
and you could integrate that state. That may be the simplest way to implement what you have, keeping in mind that if you have some more complicated function that makes the assignment, you will have to carryout the chain rule correctly.
This is not how repeated assignments are handled in SimBiology. When putting together the solvers in SimBiology we can manipulate both the right hand side of the system of differential equations and the solution of the states. We implement something a bit better from the perspective of ODE solution accuracy and speed of solution, but without knowing more about your solver, I can't advise you on how to proceed.
--Andrew
(one of the SimBiology devs)

Generate bifurcation diagram for 2D system

Drawing bifurcation diagram for 1D system is clear but if I have 2D system on the following form
dx/dt=f(x,y,r),
dy/dt=g(x,y,r)
And I want to generate a bifurcation diagram in MATLAB for x versus r.
What is the main idea to do that or any hints which could help me?
You first have to do some math:
Setting each of the functions to zero gives you two functions y(x) (called the nullclines), which you can plot in a phase diagram. Where the two lines intersect are the fixed-points (equilibria) of your system.
Now, you have to take the jacobian of your system and plug each of those fixed-points in, which will give you the linear stability analysis of the system.
The location of the fixed points and the stability of each point can now be computed as a you vary r (the bifurcation parameter).
For the programming:
-use newton's method (fsolve in MATLAB) to find where the equations are zero
-eig will help you find the eigenvalues of the system.
However
It depends on your system.
If you're supposed to be looking for limit cycles or chaos or something, you'll have to use one of the ode solvers and then the analysis becomes more tricky. I suppose you could develop a poincare-bendixson algorithm, but that would be involved and details would depend on your system.
I don't think MATLAB has anything built in that would give you a bifurcation diagram. There is this third-party solution:
http://www.mathworks.com/matlabcentral/fileexchange/8382