对于下列三个微分方程,化为现代控制非线性微分方程形式,状态向量为phi,diff(phi,t),x,diff(x,t),theta,diff(theta,t)并写出matlab代码以及写出状态空间符号表达式:I_Mdiff(phi,t,2)==T_p+Mdiff(((L+L_M)sin(theta)-lsin(phi)),t,2)lcos(phi)+Mdiff((L+L_M)cos(theta)+lcos(phi)+Mg,t,2)lsin(phi);I_pdiff(theta,t,2)==(PL+P-m_pg-m_pdiff(Lcos(theta),t,2)L_M)sin(theta)-(NL+N -m_pdiff(x+Lsin(theta),t,2)*L_M)*cos(theta)-T+T_p; ;diff(x,t,2)==(T-NR)/(I_w/R+m_wR)
时间: 2023-08-11 18:06:06 浏览: 190
第一个微分方程化为现代控制非线性微分方程形式:
```matlab
% 状态向量为 phi, diff(phi,t), x, diff(x,t), theta, diff(theta,t)
% 定义符号变量
syms phi phidot x xdot theta thetadot Tp L Lm l Mg
% 定义系统矩阵 A, 输入矩阵 B, 输出矩阵 C, 状态反馈矩阵 K
A = [0 1 0 0 0 0; (l*Mg)/(L*lcos(phi)^2+Ml) 0 0 0 (L+Lm)*lsin(phi)/(L*lcos(phi)^2+Ml) 0; 0 0 0 1 0 0; (-l*Mg*cos(phi))/(L*lcos(phi)^2+Ml) 0 0 0 -(L+Lm)*lcos(phi)/(L*lcos(phi)^2+Ml) 0; 0 0 0 0 0 1; ((l*Mg*cos(phi)+lsin(phi)*Tp)/(L*lcos(phi)^2+Ml)) 0 0 0 (-(L+Lm)*lcos(phi)*Tp+lsin(phi)*Tp)/(L*lcos(phi)^2+Ml) 0];
B = [0; (lcos(phi)/(L*lcos(phi)^2+Ml)); 0; (lsin(phi)/(L*lcos(phi)^2+Ml)); 0; (-lcos(phi)/(L*lcos(phi)^2+Ml))];
C = [1 0 0 0 0 0; 0 0 1 0 0 0; 0 0 0 0 1 0];
K = place(A, B, [-1 -1.5 -2 -2.5 -3 -3.5]); % 状态反馈控制
% 定义非线性函数 f
f = @(t, X) [X(2); (l*Mg*cos(X(1))-(L+Lm)*X(5)^2*sin(X(1)))/(L*cos(X(1))^2+Ml); X(4); ((L+Lm)*X(5)^2*cos(X(1))-l*Mg*sin(X(1)))/(L*cos(X(1))^2+Ml); X(6); ((l*Mg*cos(X(1))+X(2)*X(5)*sin(X(1)))/(L*cos(X(1))^2+Ml))];
% 定义初值条件 X0
X0 = [0, 0, 0, 0, 0, 0];
% 求解微分方程
[t, X] = ode45(f, [0 10], X0);
% 绘图
subplot(3, 1, 1);
plot(t, X(:, 1));
xlabel('时间');
ylabel('phi');
subplot(3, 1, 2);
plot(t, X(:, 3));
xlabel('时间');
ylabel('x');
subplot(3, 1, 3);
plot(t, X(:, 5));
xlabel('时间');
ylabel('theta');
% 状态空间符号表达式
syms phi phidot x xdot theta thetadot Tp L Lm l Mg
f = [phidot; (l*Mg*cos(phi)-(L+Lm)*thetadot^2*sin(phi))/(L*cos(phi)^2+Ml); xdot; ((L+Lm)*thetadot^2*cos(phi)-l*Mg*sin(phi))/(L*cos(phi)^2+Ml); thetadot; ((l*Mg*cos(phi)+phidot*thetadot*sin(phi))/(L*cos(phi)^2+Ml))];
g = [0; (l*cos(phi)/(L*cos(phi)^2+Ml)); 0; (l*sin(phi)/(L*cos(phi)^2+Ml)); 0; (-l*cos(phi)/(L*cos(phi)^2+Ml))];
h = [1 0 0 0 0 0; 0 0 1 0 0 0; 0 0 0 0 1 0];
```
第二个微分方程化为现代控制非线性微分方程形式:
```matlab
% 状态向量为 phi, diff(phi,t), x, diff(x,t), theta, diff(theta,t)
% 定义符号变量
syms phi phidot x xdot theta thetadot T NL N PL P m_theta m_x m_pg L
% 定义系统矩阵 A, 输入矩阵 B, 输出矩阵 C, 状态反馈矩阵 K
A = [0 1 0 0 0 0; 0 0 0 1 0 0; 0 0 0 0 0 1; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0];
B = [0; 0; 0; 0; 0; 1/(NL+N-m_x*m_pg)];
C = [1 0 0 0 0 0; 0 0 1 0 0 0; 0 0 0 0 1 0];
K = place(A, B, [-1 -1.5 -2 -2.5 -3 -3.5]); % 状态反馈控制
% 定义非线性函数 f
f = @(t, X) [X(2); (PL+P-m_pg-m_theta*L*cos(X(5))*X(6)^2-m_x*X(4)*X(6)^2)/(m_theta*L*sin(X(5))); X(4); (NL+N-m_x*X(6)^2-m_theta*L*cos(X(5))*X(6)^2)*sin(X(5)); X(6); ((-cos(X(5))*X(6)*(PL+P-m_pg-m_theta*L*cos(X(5))*X(6)^2-m_x*X(4)*X(6)^2)+T)/(m_theta*L^2*sin(X(5))^2))];
% 定义初值条件 X0
X0 = [0, 0, 0, 0, 0, 0];
% 求解微分方程
[t, X] = ode45(f, [0 10], X0);
% 绘图
subplot(3, 1, 1);
plot(t, X(:, 1));
xlabel('时间');
ylabel('phi');
subplot(3, 1, 2);
plot(t, X(:, 3));
xlabel('时间');
ylabel('x');
subplot(3, 1, 3);
plot(t, X(:, 5));
xlabel('时间');
ylabel('theta');
% 状态空间符号表达式
syms phi phidot x xdot theta thetadot T NL N PL P m_theta m_x m_pg L
f = [phidot; (PL+P-m_pg-m_theta*L*cos(theta)*thetadot^2-m_x*xdot^2)/(m_theta*L*sin(theta)); xdot; (NL+N-m_x*xdot^2-m_theta*L*cos(theta)*thetadot^2)*sin(theta); thetadot; ((-cos(theta)*thetadot*(PL+P-m_pg-m_theta*L*cos(theta)*thetadot^2-m_x*xdot^2)+T)/(m_theta*L^2*sin(theta)^2))];
g = [0; 0; 0; 0; 0; 1/(NL+N-m_x*m_pg)];
h = [1 0 0 0 0 0; 0 0 1 0 0 0; 0 0 0 0 1 0];
```
第三个微分方程化为现代控制非线性微分方程形式:
```matlab
% 状态向量为 phi, diff(phi,t), x, diff(x,t), theta, diff(theta,t)
% 定义符号变量
syms x xdot T NR Iw Rw Mw
% 定义系统矩阵 A, 输入矩阵 B, 输出矩阵 C, 状态反馈矩阵 K
A = [0 1; 0 0];
B = [0; (1/(Iw/Rw+Mw*Rw))];
C = [1 0];
K = place(A, B, [-1 -2]); % 状态反馈控制
% 定义非线性函数 f
f = @(t, X) [X(2); (T-NR)/(Iw/Rw+Mw*Rw)];
% 定义初值条件 X0
X0 = [0, 0];
% 求解微分方程
[t, X] = ode45(f, [0 10], X0);
% 绘图
plot(t, X(:, 1));
xlabel('时间');
ylabel('x');
% 状态空间符号表达式
syms x xdot T NR Iw Rw Mw
f = [xdot; (T-NR)/(Iw/Rw+Mw*Rw)];
g = [0; (1/(Iw/Rw+Mw*Rw))];
h = [1 0];
```
阅读全文