FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ModelicaStandardLibrary/ModelicaTest/ComplexMath.mo at master · modelscript/ModelicaStandardLibrary · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
modelscript
/
ModelicaStandardLibrary
Public
forked from
modelica/ModelicaStandardLibrary
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ModelicaStandardLibrary
/
ModelicaTest
/
ComplexMath.mo
Copy path
More file actions
More file actions
Latest commit
History
History
History
228 lines (189 loc) · 6.52 KB
Breadcrumbs
ModelicaStandardLibrary
/
ModelicaTest
/
ComplexMath.mo
Copy path
File metadata and controls
228 lines (189 loc) · 6.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
within
ModelicaTest;
package
ComplexMath
"Test functions for Complex and Modelica.ComplexMath"
extends
Modelica.Icons.ExamplesPackage;
function
ComplexFunctions
extends
Modelica.Icons.Function;
import
Complex;
input
String
logFile
=
"ModelicaTestLog.txt"
"Filename where the log is stored"
;
output
Boolean
success;
protected
Complex c1;
Complex c2;
Complex res;
Complex ref;
Real
Res;
Real
Ref;
Boolean
bRes;
Boolean
bRef;
constant
Real
epsilon
=
1E-14
;
algorithm
success
:=
false
;
Modelica.Utilities.Streams.print(
"... Test of Complex and of Modelica.ComplexMath"
);
Modelica.Utilities.Streams.print(
"... Test of Complex and of Modelica.ComplexMath"
, logFile);
c1
:=
Complex(
1
,
1
);
res
:=
-
c1;
ref
:=
Complex(
-
1
,
-
1
);
assert
(ref
==
res,
"unary minus failed"
);
c1
:=
Complex(
1
,
1
);
c2
:=
Complex(
2
,
2
);
res
:=
c1
-
c2;
ref
:=
Complex(
-
1
,
-
1
);
assert
(ref
==
res,
"subtraction failed"
);
c1
:=
Complex(
1
,
1
);
c2
:=
Complex(
2
,
2
);
res
:=
c1
+
c2;
ref
:=
Complex(
3
,
3
);
assert
(ref
==
res,
"addition failed"
);
c1
:=
Complex(
1
,
1
);
c2
:=
Complex(
2
,
2
);
res
:=
c1
*
c2;
ref
:=
Complex(
0
,
4
);
assert
(ref
==
res,
"multiplication failed"
);
c1
:=
Complex(
1
,
1
);
c2
:=
Complex(
2
,
2
);
res
:=
c1
/
c2;
ref
:=
Complex(
0.5
,
0
);
assert
(ref
==
res,
"division failed"
);
c1
:=
Complex(
1
,
1
);
c2
:=
Complex(
2
,
2
);
res
:=
c1
^
c2;
ref
:=
Complex(
-
0.265653998849241
,
+
0.319818113856136
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"power failed"
);
c1
:=
Complex(
2
,
3
);
c2
:=
Complex(
2
,
3
);
bRes
:=
c1
==
c2;
bRef
:=
true
;
assert
(bRef
==
bRes,
"Equality failed"
);
c1
:=
Complex(
2
,
5
);
c2
:=
Complex(
2
,
3
);
bRes
:=
c1
==
c2;
bRef
:=
false
;
assert
(bRef
==
bRes,
"Equality failed"
);
c1
:=
Complex(
2
,
3
);
c2
:=
Complex(
2
,
3
);
bRes
:=
c1
<>
c2;
bRef
:=
false
;
assert
(bRef
==
bRes,
"Equality failed"
);
c1
:=
Complex(
2
,
5
);
c2
:=
Complex(
2
,
3
);
bRes
:=
c1
<>
c2;
bRef
:=
true
;
assert
(bRef
==
bRes,
"Equality failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
sin
(c1);
ref
:=
Complex(
+
1.29845758141598
,
+
0.634963914784736
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"sin failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
cos
(c1);
ref
:=
Complex(
+
0.83373002513114
,
-
0.988897705762865
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"cos failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
tan
(c1);
ref
:=
Complex(
+
0.271752585319512
,
+
1.08392332733869
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"tan failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
asin
(c1);
ref
:=
Complex(
+
0.666239432492515
,
+
1.06127506190504
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"asin failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
acos
(c1);
ref
:=
Complex(
+
0.904556894302381
,
-
1.06127506190504
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"acos failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
atan
(c1);
ref
:=
Complex(
+
1.01722196789785
,
+
0.402359478108525
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"atan failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
sinh
(c1);
ref
:=
Complex(
+
0.634963914784736
,
+
1.29845758141598
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"sinh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
cosh
(c1);
ref
:=
Complex(
+
0.833730025131149
,
+
0.988897705762865
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"cosh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
tanh
(c1);
ref
:=
Complex(
+
1.08392332733869
,
+
0.271752585319512
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"tanh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.asinh(c1);
ref
:=
Complex(
+
1.06127506190504
,
+
0.666239432492515
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"asinh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.acosh(c1);
ref
:=
Complex(
+
1.06127506190504
,
+
0.904556894302381
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"acosh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.atanh(c1);
ref
:=
Complex(
+
0.402359478108525
,
+
1.01722196789785
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"atanh failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
exp
(c1);
ref
:=
Complex(
+
1.46869393991589
,
+
2.28735528717884
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"eps failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
log
(c1);
ref
:=
Complex(
+
0.346573590279973
,
+
0.785398163397448
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"log failed"
);
c1
:=
Complex(
1
,
1
);
Res
:=
Modelica.ComplexMath.
abs
(c1);
Ref
:=
sqrt
(
2
);
assert
(
abs
(Ref
-
Res)
<
epsilon,
"abs failed"
);
c1
:=
Complex(
1
,
1
);
Res
:=
Modelica.ComplexMath.arg(c1);
Ref
:=
Modelica.Constants.pi
/
4
;
assert
(
abs
(Ref
-
Res)
<
epsilon,
"arg failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.conj(c1);
ref
:=
Complex(
1
,
-
1
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"conj failed"
);
c1
:=
Complex(
1
,
1
);
Res
:=
Modelica.ComplexMath.real(c1);
Ref
:=
1
;
assert
(
abs
(Ref
-
Res)
<
epsilon,
"real failed"
);
c1
:=
Complex(
1
,
1
);
Res
:=
Modelica.ComplexMath.imag(c1);
Ref
:=
1
;
assert
(
abs
(Ref
-
Res)
<
epsilon,
"imag failed"
);
res
:=
Modelica.ComplexMath.fromPolar(
sqrt
(
2
),Modelica.Constants.pi
/
4
);
ref
:=
Complex(
1
,
1
);
assert
(
abs
(Ref
-
Res)
<
epsilon,
"fromPolar failed"
);
c1
:=
Complex(
1
,
1
);
res
:=
Modelica.ComplexMath.
sqrt
(c1);
ref
:=
Complex(
+
1.09868411346781
,
+
0.455089860562227
);
assert
(Modelica.ComplexMath.
abs
(ref
-
res)
<
epsilon,
"sqrt failed"
);
success
:=
true
;
end
ComplexFunctions;
function
ComplexOperations
extends
Modelica.Icons.Function;
output
Boolean
success;
protected
Real
a
=
2
;
Complex j
=
Modelica.ComplexMath.j;
Complex b
=
2
+
3
*
j;
Complex c
=
(
2
*
b
+
a)
/
b;
Complex d
=
Modelica.ComplexMath.
sin
(c);
Complex v[
3
]
=
{b
/
2
, c,
2
*
d};
algorithm
success
:=
true
;
end
ComplexOperations;
model
TestComplexFunctions
extends
Modelica.Icons.Example;
Boolean
result;
algorithm
when
initial
()
then
result
:=
ModelicaTest.ComplexMath.ComplexFunctions();
end when
;
annotation (experiment(StopTime=0));
end
TestComplexFunctions;
model
TestComplexOperations
extends
Modelica.Icons.Example;
Boolean
result;
algorithm
when
initial
()
then
result
:=
ModelicaTest.ComplexMath.ComplexFunctions();
end when
;
annotation (experiment(StopTime=0));
end
TestComplexOperations;
end
ComplexMath;
Back
|
FazBrowse Home
|
New Git URL