g(1)=abs(i2refa-i2a-K1*(uca-udc0))+abs(i2refb-i2b-K1(ucb-udc0))+abs(i2refc-i2c-K1(ucc-udc0)); g(2)=abs(i2refa-i2a-K1(uca-udc*(-1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(2/3))); g(3)=abs(i2refa-i2a-K1*(uca-udc*(-1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(2/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-1/3))); g(4)=abs(i2refa-i2a-K1*(uca-udc*(-2/3)))+abs(i2refb-i2b-K1*(ucb-udc*(1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(1/3))); g(5)=abs(i2refa-i2a-K1*(uca-udc*(2/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-1/3))); g(6)=abs(i2refa-i2a-K1*(uca-udc*(1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-2/3)))+abs(i2refc-i2c-K1*(ucc-udc*(1/3))); g(7)=abs(i2refa-i2a-K1*(uca-udc*(1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-2/3))); g(8)=abs(i2refa-i2a-K1*(uca-udc0))+abs(i2refb-i2b-K1(ucb-udc0))+abs(i2refc-i2c-K1(ucc-udc*0))用simulink如何实现筛选出计算所得值最小的输入状态
时间: 2023-07-15 21:11:48 浏览: 187
vim-coffeescript-refactoring:在vim中为Coffeescript重构工具!
你可以使用 MATLAB Function Block 来实现这个功能。首先,将上述代码复制到 MATLAB Function Block 中,并将输入和输出端口设置为所需的大小和数据类型。然后,在 MATLAB Function Block 中添加以下代码来计算 g 值:
```
function [g_min, state] = fcn(i2refa, i2a, i2refb, i2b, i2refc, i2c, uca, ucb, ucc, udc0, K1)
g = zeros(1,8);
g(1) = abs(i2refa-i2a-K1*(uca-udc0))+abs(i2refb-i2b-K1*(ucb-udc0))+abs(i2refc-i2c-K1*(ucc-udc0));
g(2) = abs(i2refa-i2a-K1*(uca-udc*(-1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(2/3)));
g(3) = abs(i2refa-i2a-K1*(uca-udc*(-1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(2/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-1/3)));
g(4) = abs(i2refa-i2a-K1*(uca-udc*(-2/3)))+abs(i2refb-i2b-K1*(ucb-udc*(1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(1/3)));
g(5) = abs(i2refa-i2a-K1*(uca-udc*(2/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-1/3)));
g(6) = abs(i2refa-i2a-K1*(uca-udc*(1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(-2/3)))+abs(i2refc-i2c-K1*(ucc-udc*(1/3)));
g(7) = abs(i2refa-i2a-K1*(uca-udc*(1/3)))+abs(i2refb-i2b-K1*(ucb-udc*(1/3)))+abs(i2refc-i2c-K1*(ucc-udc*(-2/3)));
g(8) = abs(i2refa-i2a-K1*(uca-udc0))+abs(i2refb-i2b-K1*(ucb-udc0))+abs(i2refc-i2c-K1*(ucc-udc*0));
[g_min, state] = min(g);
end
```
该函数将计算出每个状态的 g 值,并返回最小值及其对应的状态编号。接下来,在 Simulink 模型中,将 MATLAB Function Block 插入到合适的位置,并将输入端口连接到控制系统的输出,将输出端口连接到一个 MinMax Block。在 MinMax Block 中,选择“Minimum”作为操作,即可实现筛选出计算所得值最小的输入状态的功能。
阅读全文