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

조회 수: 14 (최근 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 CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by