单容水箱液位模糊控制matlab
时间: 2023-09-03 12:12:11 浏览: 101
水箱液位matlab模糊控制例程sltank详解.docx
5星 · 资源好评率100%
单容水箱液位模糊控制可以使用模糊控制器来实现。模糊控制器是一种基于模糊逻辑的控制器,可以处理模糊或不确定的输入和输出。
下面是一个用Matlab实现单容水箱液位模糊控制的示例:
1. 定义模糊变量
```
water_level = newfis('water_level');
%定义输入变量
water_level = addvar(water_level,'input','water_level',[0 100]);
water_level = addmf(water_level,'input',1,'low','trapmf',[0 0 20 30]);
water_level = addmf(water_level,'input',1,'medium','trimf',[20 40 60]);
water_level = addmf(water_level,'input',1,'high','trapmf',[50 70 100 100]);
%定义输出变量
water_flow = addvar(water_level,'output','water_flow',[0 10]);
water_flow = addmf(water_level,'output',1,'low','trapmf',[0 0 2 4]);
water_flow = addmf(water_level,'output',1,'medium','trimf',[2 5 8]);
water_flow = addmf(water_level,'output',1,'high','trapmf',[6 8 10 10]);
```
2. 设计模糊规则
```
%定义模糊规则
rule1 = [1 1 1 1];
rule2 = [2 2 2 1];
rule3 = [3 3 3 1];
rule4 = [1 2 2 2];
rule5 = [2 3 3 2];
rule6 = [3 1 1 2];
rule7 = [1 3 2 3];
rule8 = [2 1 3 3];
rule9 = [3 2 1 3];
%添加规则
rules = [rule1; rule2; rule3; rule4; rule5; rule6; rule7; rule8; rule9];
water_level = addrule(water_level,rules);
```
3. 定义输入
```
%定义输入
water_level_input = 50;
```
4. 模糊推理
```
%模糊推理
water_flow_output = evalfis(water_level,[water_level_input]);
```
5. 显示输出
```
%显示输出
fprintf('水位为%.2f时,水流量为%.2f\n',water_level_input,water_flow_output);
```
这个例子中,我们定义了水位和水流量两个模糊变量。水位有低、中、高三个模糊集,水流量有低、中、高三个模糊集。然后我们根据经验定义了一些模糊规则,例如“如果水位高,那么水流量也高”。最后根据输入水位进行模糊推理,得到输出水流量。
阅读全文