基于MATLAB的模糊控制系统例子
时间: 2023-07-26 16:33:42 浏览: 121
以下是一个基于 MATLAB 的模糊控制系统例子,实现了一个简单的温度控制系统:
首先,我们需要定义输入变量和输出变量的模糊集。在本例中,我们要控制的是一个加热器的温度,输入变量是当前温度偏差(e)和温度变化率(de),输出变量是加热器的功率(u)。我们可以定义以下模糊集:
```matlab
% 定义输入变量的模糊集
e = -10:0.1:10; % 温度偏差
de = -10:0.1:10; % 温度变化率
% 定义输出变量的模糊集
u = 0:0.1:1; % 加热器功率
```
然后,我们需要定义模糊规则。在本例中,我们使用以下规则:
```matlab
ruleList = [
1, 1, 1;
1, 2, 1;
2, 1, 1;
2, 2, 2;
];
```
这些规则定义了四个输入变量的组合,以及相应的输出变量。例如,第一行规则表示当温度偏差为“NB”(“Negative Big”)并且温度变化率为“NB”时,加热器功率为“NB”。
接下来,我们需要创建模糊系统并添加变量和模糊集:
```matlab
% 创建模糊系统
fis = newfis('FIS_SCARA');
% 添加输入变量和模糊集
fis = addvar(fis, 'input', 'e', [-10 10]);
fis = addmf(fis, 'input', 1, 'NB', 'gaussmf', [1.5 -10]);
fis = addmf(fis, 'input', 1, 'NM', 'gaussmf', [1.5 -5]);
fis = addmf(fis, 'input', 1, 'NS', 'gaussmf', [1.5 -2.5]);
fis = addmf(fis, 'input', 1, 'ZO', 'gaussmf', [1.5 0]);
fis = addmf(fis, 'input', 1, 'PS', 'gaussmf', [1.5 2.5]);
fis = addmf(fis, 'input', 1, 'PM', 'gaussmf', [1.5 5]);
fis = addmf(fis, 'input', 1, 'PB', 'gaussmf', [1.5 10]);
fis = addvar(fis, 'input', 'de', [-10 10]);
fis = addmf(fis, 'input', 2, 'NB', 'gaussmf', [1.5 -10]);
fis = addmf(fis, 'input', 2, 'NM', 'gaussmf', [1.5 -5]);
fis = addmf(fis, 'input', 2, 'NS', 'gaussmf', [1.5 -2.5]);
fis = addmf(fis, 'input', 2, 'ZO', 'gaussmf', [1.5 0]);
fis = addmf(fis, 'input', 2, 'PS', 'gaussmf', [1.5 2.5]);
fis = addmf(fis, 'input', 2, 'PM', 'gaussmf', [1.5 5]);
fis = addmf(fis, 'input', 2, 'PB', 'gaussmf', [1.5 10]);
% 添加输出变量和模糊集
fis = addvar(fis, 'output', 'u', [0 1]);
fis = addmf(fis, 'output', 1, 'NB', 'gaussmf', [0.1 0]);
fis = addmf(fis, 'output', 1, 'NM', 'gaussmf', [0.1 0.25]);
fis = addmf(fis, 'output', 1, 'NS', 'gaussmf', [0.1 0.5]);
fis = addmf(fis, 'output', 1, 'ZO', 'gaussmf', [0.1 0.5]);
fis = addmf(fis, 'output', 1, 'PS', 'gaussmf', [0.1 0.75]);
fis = addmf(fis, 'output', 1, 'PM', 'gaussmf', [0.1 1]);
fis = addmf(fis, 'output', 1, 'PB', 'gaussmf', [0.1 1]);
% 添加规则
fis = addrule(fis, ruleList);
```
最后,我们可以使用 MATLAB 中的 evalfis 函数来评估模糊系统并进行控制:
```matlab
% 模拟加热器控制
t = 0:0.1:50;
x = zeros(size(t));
xs = 50;
e(1) = xs - x(1);
for i = 2:length(t)
de(i) = (e(i) - e(i-1)) / 0.1; % 计算温度变化率
u(i) = evalfis([e(i) de(i)], fis); % 使用模糊控制器计算加热器功率
x(i) = x(i-1) + u(i) * 0.1; % 计算温度
e(i) = xs - x(i); % 计算温度偏差
end
plot(t, x)
```
在这个例子中,我们使用模糊控制器来控制加热器的温度。我们使用 evalfis 函数来评估模糊系统并计算加热器的功率,然后模拟加热器温度随时间的变化曲线。
阅读全文
相关推荐

















