1 | |
---|

2 | Model Baskara |
---|

3 | |
---|

4 | # This model calculates Y = ax^+bx+c = 0 , where a = 1 if a=0 |
---|

5 | |
---|

6 | PARAMETERS |
---|

7 | |
---|

8 | Roots as Switcher (Valid = ["equal roots", "different roots" , "complex"], Default = "equal roots"); |
---|

9 | |
---|

10 | PARAMETERS |
---|

11 | |
---|

12 | a as Real; |
---|

13 | b as Real; |
---|

14 | c as Real; |
---|

15 | |
---|

16 | VARIABLES |
---|

17 | |
---|

18 | delta as Real; |
---|

19 | a_protected as Real; |
---|

20 | x1(2) as Real; |
---|

21 | x2(2) as Real; |
---|

22 | |
---|

23 | EQUATIONS |
---|

24 | |
---|

25 | if a equal 0 |
---|

26 | then |
---|

27 | a_protected = 1; |
---|

28 | |
---|

29 | else |
---|

30 | a_protected = a; |
---|

31 | |
---|

32 | end |
---|

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 | |
---|

71 | end |
---|

72 | |
---|

73 | end |
---|

74 | |
---|

75 | FlowSheet Test |
---|

76 | |
---|

77 | DEVICES |
---|

78 | dev as Baskara; |
---|

79 | |
---|

80 | SET |
---|

81 | |
---|

82 | dev.a=0; |
---|

83 | dev.b=2; |
---|

84 | dev.c=12; |
---|

85 | |
---|

86 | #dev.Roots = "complex"; |
---|

87 | |
---|

88 | OPTIONS |
---|

89 | Dynamic = false; |
---|

90 | |
---|

91 | end |
---|