Non linear EOM Using Simulink

조회 수: 17 (최근 30일)
Amirhossein Daliri Shadbad
Amirhossein Daliri Shadbad 2022년 5월 15일
답변: Pramil 2024년 2월 21일
My system is a chain of repelling magnets with n magnets.
I'm trying to develop the Simulink model (attached) to solve the non-linear EOM, attached. The equations of motion of the first and last (n-th) elements are different, but EOM of middle magnets are the same and given as
A, p (negative value) , d0, and m are constants. fn is the external force that is applied to the nth magnet. The problem arises when I want to be able to vary the number of magnets. I have the following Simulink model, where I have put all of the non-linear EOM in a function
Where the EOM function is, n is an input.
function x_dd = EOM(m, A, p, d0, n, f, x)
M = m*eye(n); %The Mass Matrix
F = zeros(n,1); %Initializing Force matrix
g = 9.81; %Gravitational Constant
F(1,1) = (A*(d0+x(1))^(p)) - (A*(d0+x(2)-x(1))^(p)); %Equalivalnt force of first element
F(n,1) = fn + (A*(d0+x(n)-x(n-1))^(p)); %Equalivalnt force of last element
for ii=2:n-1
F(ii,1) = -(A*(d0+x(ii+1)-x(ii))^(p)) + (A*(d0+x(ii)-x(ii-1))^(p)); %Equalivalnt force of ith element
end
x_dd = inv(M)*[F];
end
I don't know why this isn't working, but I think the integrator outputs single values not a vector (that would include all degrees of freedom). If I didn't want to change the number of magnets, n, I could do something similar to this (n=4);
  댓글 수: 1
Amirhossein Daliri Shadbad
Amirhossein Daliri Shadbad 2022년 5월 16일
Basically I'm trying to integrate multiple x's at the same time with a single integrator block and I think that's what's causing the issue.

댓글을 달려면 로그인하십시오.

답변 (1개)

Pramil
Pramil 2024년 2월 21일
So, the issue can be resolved through a workaround by not taking “n” as an input parameter, but a block parameter.
You can do this by double clicking your “MATLAB Function block”, go to MODELING->Symbols Pane, a side window with variables will be opened. Now select “n” and left click on it, mark it as “Parameter Data.
Go to SIMULATION tab and click on property Inspector and make sure that for n, the “Tunable” check box is unchecked.
Now you can define n, anywhere either in your base workspace or model workspace, it should just work fine.
I have attached a model for your reference, the model works on both MATLAB R2022a and R2023b.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by