summaryrefslogtreecommitdiff
path: root/examples/takagi-sugeno/approximation.fcl
blob: 8b5f1213edd5ca609e4304317a63b3b5ec68cd2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
FUNCTION_BLOCK approximation of sin(x)/x

VAR_INPUT
  inputX: REAL;
END_VAR

VAR_OUTPUT
  outputFx: REAL;
  trueFx: REAL;
  diffFx: REAL;
END_VAR

FUZZIFY inputX
  RANGE := (0.000 .. 10.000);
  TERM NEAR_1 := Triangle 0.000 1.000 2.000;
  TERM NEAR_2 := Triangle 1.000 2.000 3.000;
  TERM NEAR_3 := Triangle 2.000 3.000 4.000;
  TERM NEAR_4 := Triangle 3.000 4.000 5.000;
  TERM NEAR_5 := Triangle 4.000 5.000 6.000;
  TERM NEAR_6 := Triangle 5.000 6.000 7.000;
  TERM NEAR_7 := Triangle 6.000 7.000 8.000;
  TERM NEAR_8 := Triangle 7.000 8.000 9.000;
  TERM NEAR_9 := Triangle 8.000 9.000 10.000;
END_FUZZIFY

DEFUZZIFY outputFx
  RANGE := (-1.000 .. 1.000);
  TERM f1 := 0.840;
  TERM f2 := 0.450;
  TERM f3 := 0.040;
  TERM f4 := -0.180;
  TERM f5 := -0.190;
  TERM f6 := -0.040;
  TERM f7 := 0.090;
  TERM f8 := 0.120;
  TERM f9 := 0.040;
  METHOD : COGS;
  DEFAULT := nan | NC;
END_DEFUZZIFY

DEFUZZIFY trueFx
  RANGE := (-1.000 .. 1.000);
  TERM fx := Function sin(inputX)/inputX;
  METHOD : COGS;
  DEFAULT := nan | NC;
END_DEFUZZIFY

DEFUZZIFY diffFx
  RANGE := (-1.000 .. 1.000);
  TERM diff := Function fabs(outputFx-trueFx);
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

RULEBLOCK 
  RULE 1 : if inputX is NEAR_1 then outputFx is f1
  RULE 2 : if inputX is NEAR_2 then outputFx is f2
  RULE 3 : if inputX is NEAR_3 then outputFx is f3
  RULE 4 : if inputX is NEAR_4 then outputFx is f4
  RULE 5 : if inputX is NEAR_5 then outputFx is f5
  RULE 6 : if inputX is NEAR_6 then outputFx is f6
  RULE 7 : if inputX is NEAR_7 then outputFx is f7
  RULE 8 : if inputX is NEAR_8 then outputFx is f8
  RULE 9 : if inputX is NEAR_9 then outputFx is f9
  RULE 10 : if inputX is any  then trueFx is fx and diffFx is diff
END_RULEBLOCK

END_FUNCTION_BLOCK