# Ticket #121: Bug_switcher.mso

File Bug_switcher.mso, 1.4 KB (added by gerson bicca, 15 years ago)
Line
1
3
4# This model calculates Y = ax^+bx+c = 0 , where a = 1 if a=0
5
6PARAMETERS
7
8    Roots  as Switcher  (Valid = ["equal roots", "different roots" , "complex"], Default = "equal roots");
9
10PARAMETERS
11
12        a       as Real;
13        b       as Real;
14        c       as Real;
15
16VARIABLES
17
18        delta                   as Real;
19        a_protected     as Real;
20        x1(2)                   as Real;
21        x2(2)                   as Real;
22
23EQUATIONS
24
25if a equal 0
26        then
27        a_protected = 1;
28
29        else
30        a_protected = a;
31
32end
33
34        delta = b*b-4*a_protected*c;
35
36 switch Roots
37
38        case "equal roots":
39        x1(1) = -b/(2*a_protected) ;
40        x1(2) = 0 ;
41
42        x2(1) = x1(1);
43        x2(2) = 0 ;
44
45        when delta > 0  switchto "different roots";
46
47        when delta < 0  switchto "complex";
48
49        case "different roots":
50        x1(1) = (-b+sqrt(delta))/(2*a_protected) ;
51        x1(2) = 0 ;
52
53        x2(1) = (-b-sqrt(delta))/(2*a_protected) ;
54        x2(2) = 0;
55
56        when delta < 0  switchto "complex";
57
58        when delta equal 0  switchto "equal roots";
59
60        case "complex":
61        x1(1) = -b/(2*a_protected) ;
62        x1(2) = sqrt(abs(delta))/(2*a_protected) ;
63
64        x2(1) = -b/(2*a_protected) ;
65        x2(2) = -sqrt(abs(delta))/(2*a_protected) ;
66
67        when delta > 0  switchto "different roots";
68
69        when delta equal 0  switchto "equal roots";
70
71end
72
73end
74
75FlowSheet Test
76
77DEVICES