Non linear EOM Using Simulink

17 Ansichten (letzte 30 Tage)
Amirhossein Daliri Shadbad
Beantwortet: Pramil am 21 Feb. 2024
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 Kommentar
Amirhossein Daliri Shadbad
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pramil
Pramil am 21 Feb. 2024
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.

Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by