I want to build a double pendulum system in Simulink but am getting errors relating to the tolerance and step size
16 views (last 30 days)
Show older comments
How do I solve this coupled second order differential equation.


Errors:

Right now it uses ode45 to solve it but I have tried every model, added the memory block, changed the initial conditions to be smaller, changed the max step size and relative errors but nothing works.
Answers (1)
Sam Chak
on 17 May 2025
Hi @Jishnu
After reviewing the block diagram, if you feed the signals
and
(before the integrators) back into their respective loops, this will most likely create an algebraic loop error similar to that of a flip-flop circuit, as you do not have the initial values for both
and
signals. To calculate
, you need the
signal. Conversely, to calculate
, you need the
signal. This creates an unresolvable loop.
You should decouple the dynamics of
and
. This is the reason I previously advised you to work out the equations in MATLAB. If you have experience in solving coupled ODEs in MATLAB, you would already know how to decouple them. Essentially, you need to first solve the equations algebraically so that
and
.

2 Comments
Sam Chak
on 18 May 2025
Hi @Jishnu
Great! Decoupling the equations is analogous to the process of solving simultaneous equations in eighth or ninth grade mathematics. Treat
as x and
as y, while considering the other terms as either coefficients or lumped constants. You can perform this in the Symbolic Math Toolbox.
Please use a Live Script:
%% declare the symbolic variables
syms x y
syms c [2 2] % as coefficients
syms d [1 2] % as lumped constants
%% double check the irresistible Cambria Math font
disp(x)
disp(y)
disp(c)
disp(d)
%% equation 1
eq1 = c(1,1)*x + c(1,2)*y == d1
%% equation 2
eq2 = c(2,1)*x + c(2,2)*y == d2
%% no-pen-and-paper solution
[x, y] = solve([eq1, eq2], [x, y])
%% Hmm... The denominator looks familiar
det(c)
%% Let's ask for "help" to see what det() is
help det
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
