1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2007 ALSOC, original code |
---|
9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
14 | * |
---|
15 | *-------------------------------------------------------------------- |
---|
16 | * Sample file for matrix functions. |
---|
17 | *-------------------------------------------------------------------- |
---|
18 | * Author: Rodolfo Rodrigues |
---|
19 | * $Id: Matrix_Function.mso 89 2006-12-14 20:29:34Z bicca $ |
---|
20 | *------------------------------------------------------------------*# |
---|
21 | # |
---|
22 | # EMSO sample file of matrix functions |
---|
23 | # |
---|
24 | # -------------------------------------------------------- |
---|
25 | # Function | EMSO Built-In |
---|
26 | # -------------------------------------------------------- |
---|
27 | # Sum matrix elements | sum |
---|
28 | # product matrix elements | prod |
---|
29 | # Sum transpose matrix elements | sumt |
---|
30 | # product transpose matrix elements | prodt |
---|
31 | # transpose matrix |transp |
---|
32 | # |
---|
33 | #++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
34 | |
---|
35 | #*--------------------------------------------------- |
---|
36 | * |
---|
37 | * Given the matrix A: |
---|
38 | * |
---|
39 | * |-2 3 1 0| |
---|
40 | * |-1 -1 0 2| |
---|
41 | * | 0 5 1 0| |
---|
42 | * |
---|
43 | *--------------------------------------------------*# |
---|
44 | |
---|
45 | FlowSheet Matrix_Function |
---|
46 | PARAMETERS |
---|
47 | M as Integer; |
---|
48 | N as Integer; |
---|
49 | A(M,N) as Real; |
---|
50 | |
---|
51 | |
---|
52 | VARIABLES |
---|
53 | Sumt_(M) as Real; |
---|
54 | Sum_(N) as Real; |
---|
55 | |
---|
56 | Prodt_(M) as Real; |
---|
57 | Prod_(N) as Real; |
---|
58 | |
---|
59 | Transp_(N,M)as Real; |
---|
60 | |
---|
61 | |
---|
62 | SET |
---|
63 | M = 3; # rows |
---|
64 | N = 4; # columns |
---|
65 | |
---|
66 | A(:,1) = [-2, -1, 0]; |
---|
67 | A(:,2) = [ 3, -1, 5]; |
---|
68 | A(:,3) = [ 1, 0, 1]; |
---|
69 | A(:,4) = [ 0, 2, 0]; |
---|
70 | |
---|
71 | |
---|
72 | EQUATIONS |
---|
73 | #*--------------------------------------------------- |
---|
74 | * |
---|
75 | * |-2 3 1 0| |
---|
76 | * sum|-1 -1 0 2| = |-3 7 2 2| |
---|
77 | * | 0 5 1 0| |
---|
78 | * |
---|
79 | *---------------------------------------------------*# |
---|
80 | "Function sum" |
---|
81 | Sum_ = sum(A); |
---|
82 | |
---|
83 | |
---|
84 | #*--------------------------------------------------- |
---|
85 | * |
---|
86 | * |-2 3 1 0| | 2| |
---|
87 | * sumt|-1 -1 0 2| = | 0| |
---|
88 | * | 0 5 1 0| | 6| |
---|
89 | * |
---|
90 | *---------------------------------------------------*# |
---|
91 | "Function sumt" |
---|
92 | Sumt_ = sumt(A); |
---|
93 | |
---|
94 | |
---|
95 | #*--------------------------------------------------- |
---|
96 | * |
---|
97 | * |-2 3 1 0| |
---|
98 | * prod|-1 -1 0 2| = | 0 -15 0 0| |
---|
99 | * | 0 5 1 0| |
---|
100 | * |
---|
101 | *---------------------------------------------------*# |
---|
102 | "Function prod" |
---|
103 | Prod_ = prod(A); |
---|
104 | |
---|
105 | |
---|
106 | #*--------------------------------------------------- |
---|
107 | * |
---|
108 | * |-2 3 1 0| | 0| |
---|
109 | * prodt|-1 -1 0 2| = | 0| |
---|
110 | * | 0 5 1 0| | 0| |
---|
111 | * |
---|
112 | *---------------------------------------------------*# |
---|
113 | "Function prod" |
---|
114 | Prodt_ = prodt(A); |
---|
115 | |
---|
116 | |
---|
117 | #*--------------------------------------------------- |
---|
118 | * |
---|
119 | * |-2 3 1 0| |-2 -1 0| |
---|
120 | * transp|-1 -1 0 2| = | 3 -1 5| |
---|
121 | * | 0 5 1 0| | 1 0 1| |
---|
122 | * | 0 2 0| |
---|
123 | * |
---|
124 | *---------------------------------------------------*# |
---|
125 | "Function transp" |
---|
126 | Transp_ = transp(A); |
---|
127 | |
---|
128 | |
---|
129 | OPTIONS |
---|
130 | Dynamic = false; |
---|
131 | end |
---|