I want to build a double pendulum system in Simulink but am getting errors relating to the tolerance and step size

11 ビュー (過去 30 日間)
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.
  2 件のコメント
Sam Chak
Sam Chak 2025 年 5 月 16 日
Both differential equations do not contain any mathematical term that is equivalent to this Memory block.
Additionally, could you first run the simulation in MATLAB using the ode45() command? If successful, then migrate it to Simulink. You can also compare the results with MATLAB later.
Jishnu
Jishnu 2025 年 5 月 17 日
I had added the memory block as a delay function to try and fix the errors but it didn't do much. As for the simulation, I'll try to do it on Matlab but this itself is an attempt to migrate code into simulink to solve this coupled secod order differential equation. I have done it once using backward Euler and I want to try to do it using simulink. Can you please suggest the settings for the solver that will remove the errors mentioned before?

サインインしてコメントする。

回答 (1 件)

Sam Chak
Sam Chak 2025 年 5 月 17 日
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 件のコメント
Jishnu
Jishnu 2025 年 5 月 17 日
Ok I understad the problem now. Thank you. I'll try decoupling and creating a new flow and see if it works.
Sam Chak
Sam Chak 2025 年 5 月 18 日
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)
x
disp(y)
y
disp(c)
disp(d)
%% equation 1
eq1 = c(1,1)*x + c(1,2)*y == d1
eq1 = 
%% equation 2
eq2 = c(2,1)*x + c(2,2)*y == d2
eq2 = 
%% no-pen-and-paper solution
[x, y] = solve([eq1, eq2], [x, y])
x = 
y = 
%% Hmm... The denominator looks familiar
det(c)
ans = 
%% Let's ask for "help" to see what det() is
help det
det - Matrix determinant This MATLAB function returns the determinant of square matrix A. Syntax d = det(A) Input Arguments A - Input matrix square numeric matrix Examples openExample('matlab/CalculateDeterminantofMatrixExample') openExample('matlab/DetermineifMatrixIsSingularExample') openExample('matlab/FindDeterminantofSingularMatrixExample') See also cond, rcond, condest, inv, lu, rref, mldivide Introduced in MATLAB before R2006a Documentation for det doc det Other uses of det gpuArray/det laurentMatrix/det laurmat/det sym/det

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by