# Is there a way to execute the following matlab function of a system of 1st order differentail equations from within Simulink?

1 ビュー (過去 30 日間)
Tom Beekhuysen 2018 年 12 月 30 日

These are the equaitons of a cart/inverted pendulum (theta=pi is up. y1=poistion, y2=velocity, y3=theta, y4=thetadot) and i wanted to run them in simulink to test my controller which was designed on a linearized version.
function dy = cartpend(y,m,M,L,g,d,u)
m = 1;
M = 5;
L = 2;
g = -10;
d = 1;
Sy = sin(y(3));
Cy = cos(y(3));
D = m*L*L*(M+m*(1-Cy^2));
dy(1,1) = y(2);
dy(2,1) = (1/D)*(-m^2*L^2*g*Cy*Sy + m*L^2*(m*L*y(4)^2*Sy - d*y(2))) + m*L*L*(1/D)*u;
dy(3,1) = y(4);
dy(4,1) = (1/D)*((m+M)*m*g*L*Sy - m*L*Cy*(m*L*y(4)^2*Sy - d*y(2))) - m*L*Cy*(1/D)*u;
##### 1 件のコメント表示非表示 なし
madhan ravi 2018 年 12 月 30 日
why not use a matlab function block?

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

### 回答 (1 件)

Tom Beekhuysen 2018 年 12 月 30 日
I did on the attached but got errors. It said unrecognized variable for dy and a bunch of other errors. I attached my slx file.

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

### Community Treasure Hunt

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

Start Hunting!