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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
|
package gsl
package data_types
model gsl_permutation
extends ExternalObject;
function constructor
input Integer N;
output gsl_permutation p;
external "C" p = gsl_permutation_alloc(N) annotation(
Include = "#include <gsl/gsl_permutation.h>",
Library = "gsl",
Library = "gslcblas");
end constructor;
function destructor "Release storage of p"
input gsl_permutation p;
external "C" gsl_permutation_free(p) annotation(
Include = "#include <gsl/gsl_permutation.h>",
Library = "gsl",
Library = "gslcblas");
end destructor;
end gsl_permutation;
/* model gsl_complex
extends ExternalObject;
function constructor
input Integer N;
output gsl_complex k;
external "C" annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_complex.h>");
end constructor;
function destructor
input gsl_complex k;
external "C" annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_complex.h>");
end destructor;
end gsl_complex;
*/
end data_types;
package mathematical
function gsl_log1p
//This function computes the value of log(1 + x) in a way that is accurate for small x
input Real x;
output Real y;
external "C" y = log1p(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_log1p;
function gsl_expm1
//this function computes the value of exp(x)-1
input Real x;
output Real y;
external "C" y = gsl_expm1(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_expm1;
function gsl_hypot
//this function computes the value of sqrt(x^2+y^2) in a way which avoids overflow
input Real x;
input Real y;
output Real z;
external "C" z = gsl_hypot(x, y) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_hypot;
function gsl_hypot3
//This function calculates the value of sqrt(x^2+y^2+z^2)
input Real x;
input Real y;
input Real z;
output Real o;
external "C" o = gsl_hypot3(x, y, z) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_hypot3;
function gsl_acosh
// this function calculates the value of arccosh(x)
input Real x;
output Real y;
external "C" y = acosh(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_acosh;
function gsl_asinh
// this function calculates the value of arcsinh(x)
input Real x;
output Real y;
external "C" y = asinh(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_asinh;
function gsl_atanh
// this function calculates the value of arctanh(x)
input Real x;
output Real y;
external "C" y = atanh(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_atanh;
function gsl_ldexp
//this function computes the value of x*2^e
input Real x;
// y should be given the value e
output Real z;
protected
constant Real y = Modelica.Constants.e;
external "C" z = gsl_ldexp(x, y) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end gsl_ldexp;
function gsl_frexp
//This function splits the number x into its normalized fraction f and exponent e, such that x = f ∗ 2^e
// and 0.5 <= f < 1. The function returns f and stores the exponent in e.
input Real x;
output Integer e;
// it stores the exponent in y
output Real z;
external "C" z = gsl_frexp(x, e) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_frexp;
function gsl_pow_int
//this function computes x^n
input Real x;
input Integer n;
output Real y;
external "C" y = gsl_pow_int(x, n) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_int;
function gsl_pow_2
//This function calculates square fo the given number
input Real x;
output Real y;
external "C" y = gsl_pow_2(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_2;
function gsl_pow_3
//This function calculates cube of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_3(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_3;
function gsl_pow_4
//This function calculates number to the power of 4 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_4(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_4;
function gsl_pow_5
//This function calculates number to the power of 5 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_5(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_5;
function gsl_pow_6
//This function calculates number to the power of 6 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_6(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_6;
function gsl_pow_7
//This function calculates number to the power of 6 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_7(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_7;
function gsl_pow_8
//This function calculates number to the power of 6 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_8(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_8;
function gsl_pow_9
//This function calculates number to the power of 6 of the given number
input Real x;
output Real y;
external "C" y = gsl_pow_9(x) annotation(
Library = "gsl",
Library = "gslcblas");
end gsl_pow_9;
function GSL_SIGN
//This function outputs -1 for negative number and +1 if the number is positive
input Real x;
output Integer y;
external "C" y = GSL_SIGN(x) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_SIGN;
function GSL_IS_ODD
//This function outputs 1 if number is odd else if number is even it returns zero
input Integer x;
output Integer y;
external "C" y = GSL_IS_ODD(x) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_IS_ODD;
function GSL_IS_EVEN
//This function outputs 0 if number is odd else if number is even it returns 1
input Integer x;
output Integer y;
external "C" y = GSL_IS_EVEN(x) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_IS_EVEN;
function GSL_MAX
// This function calculates the maximum of two numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MAX(a, b) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MAX;
function GSL_MAX_DBL
// This function calculates the maximum of the given two floating point numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MAX_DBL(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MAX_DBL;
function GSL_MIN_DBL
//This function calculates the minimum of two given floating point numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MIN_DBL(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MIN_DBL;
function GSL_MAX_INT
// This function calculates the maximum of two given integers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MAX_INT(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MAX_INT;
function GSL_MIN_INT
// This function calculates the minimum of the two numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MIN_INT(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MIN_INT;
function GSL_MAX_LDBL
// This function calculates the maximum of two long double numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MAX_LDBL(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MAX_LDBL;
function GSL_MIN_LDBL
// This function calculates the minimum of two long double numbers
input Real a;
input Real b;
output Real c;
external "C" c = GSL_MIN_LDBL(a, b) annotation(
Inline = true,
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end GSL_MIN_LDBL;
function gsl_fcmp
//This function determines whether x and y are approximately equal if they are equal within the range of epsilon it returns zero,if a>b it returns -1 and if b<a it returns 1
input Real a;
input Real b;
output Real c;
protected
constant Real z = Modelica.Constants.eps;
external "C" c = gsl_fcmp(a, b, z) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_math.h>");
end gsl_fcmp;
/**/
end mathematical;
package COMPLEX
function gsl_complex_rect
input Real x = 4;
input Real y = 5;
output Complex z;
external "C" z = gsl_complex_rect(x, y) annotation(
Library = "gsl",
Library = "gslcblas",
Include = "#include<gsl/gsl_complex.h>",
Include = "#include<gsl/gsl_complex_math.h>");
end gsl_complex_rect;
end COMPLEX;
package Permutation
function gsl_permutation_init
input gsl.data_types.gsl_permutation p;
external "C" gsl_permutation_init(p) annotation(
Include = "#include <gsl/gsl_permutation.h>",
Library = "gsl",
Library = "gslcblas");
end gsl_permutation_init;
function gsl_permutation_get
input gsl.data_types.gsl_permutation p;
input Integer i;
output Integer y;
external "C" y = gsl_permutation_get(p, i) annotation(
Include = "#include <gsl/gsl_permutation.h>",
Library = "gsl",
Library = "gslcblas");
end gsl_permutation_get;
function gsl_ran_shuffle
input gsl.data_types.gsl_rng r;
input gsl.data_types.gsl_permutation p;
input Integer N;
external "C" gsl_ran_shuffle(r, p, N, 8) annotation(
Include = "#include <gsl/gsl_permutation.h>",
Include = "#include <gsl/gsl_rng.h>",
Include = "#include <gsl/gsl_randist.h>",
Library = "gsl",
Library = "gslcblas");
end gsl_ran_shuffle;
/*gsl_ran_shuffle(r, p.data, N, sizeof(size_t))*/
end Permutation;
package Examples
package Mathematical
model gsl_log1p
//This model computes the value of log(1 + x) in a way that is accurate for small x by calling the function gsl_log1p(x)
parameter Real x = 0.01;
Real y;
algorithm
y := gsl.mathematical.gsl_log1p(x);
end gsl_log1p;
model gsl_expm1
//This model computes the value of exp(x)-1 in a way that is accurate for small x by calling the function gsl_expm1
parameter Real x = 0.01;
Real y;
algorithm
y := gsl.mathematical.gsl_expm1(x);
end gsl_expm1;
model gsl_hypot
//it calculates the value of sqrt(x^2+y^2)
parameter Real x = 2;
parameter Real y = 2.1;
Real z;
algorithm
z := gsl.mathematical.gsl_hypot(x, y);
end gsl_hypot;
model gsl_hypot3
//this example calculates the value of sqrt(x^2+y^2+z^2) by calling the function gsl_hypot3
parameter Real x = 2.0;
parameter Real y = 2.1;
parameter Real z = 2.2;
Real o;
algorithm
o := gsl.mathematical.gsl_hypot3(x, y, z);
end gsl_hypot3;
model gsl_acosh
//this example calls gsl_acosh to calculate the inverse of cosh
parameter Real x = 2;
Real y;
algorithm
y := gsl.mathematical.gsl_acosh(x);
end gsl_acosh;
model gsl_asinh
//this example calls gsl_asinh to calculate the inverse of sinh
parameter Real x = 2;
Real y;
algorithm
y := gsl.mathematical.gsl_asinh(x);
end gsl_asinh;
model gsl_atanh
//this example calls gsl_atanh to calculate the inverse of tanh
parameter Real x = 0.5;
Real y;
algorithm
y := gsl.mathematical.gsl_atanh(x);
end gsl_atanh;
model gsl_ldexp
//this function computes the value of x*2^e by calling the function gsl_ldexp
parameter Real x = 2.0;
// constant Real y = Modelica.Constants.e;
// y should be given the value e
Real z;
algorithm
z := gsl.mathematical.gsl_ldexp(x);
end gsl_ldexp;
model gsl_frexp
//This model calls the function gsl_frexp and splits the number x into its normalized fraction f and exponent e, such that x = f ∗ 2^e
// and 0.5 <= f < 1. The function returns f and stores the exponent in e.
parameter Real x = 2;
Integer e;
// it stores the exponent in y
output Real z;
algorithm
(e, z) := gsl.mathematical.gsl_frexp(x);
end gsl_frexp;
model gsl_pow_int
//this function computes x^n
parameter Real x = 2.0;
parameter Integer n = 2;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_int(x, n);
end gsl_pow_int;
model gsl_pow_2
//This function calculates square fo the given number
parameter Real x = 2.2;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_2(x);
end gsl_pow_2;
model gsl_pow_3
//This function calculates cube of the given number
parameter Real x = 2.02;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_3(x);
end gsl_pow_3;
model gsl_pow_4
//This function calculates number to the power of 4 of the given number
parameter Real x = 0.02;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_4(x);
end gsl_pow_4;
model gsl_pow_5
//This model calculates number to the power of 5 of the given number by calling the function gsl_pow_5(x)
parameter Real x = 0.2;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_5(x);
end gsl_pow_5;
model gsl_pow_6
//This model calculates number to the power of 6 of the given number by calling the the function gsl_pow_6(x)
parameter Real x = 2.0;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_6(x);
end gsl_pow_6;
model gsl_pow_7
//This function calculates number to the power of 7 by calling the function gsl_pow_7(x)
parameter Real x = 2.0;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_7(x);
end gsl_pow_7;
model gsl_pow_8
//This model calculates number to the power of 8 by calling the function gsl_pow_8
parameter Real x = 2.2;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_8(x);
end gsl_pow_8;
model gsl_pow_9
//This function calculates number to the power of 9 of the given number
parameter Real x = 2.2;
Real y;
algorithm
y := gsl.mathematical.gsl_pow_9(x);
end gsl_pow_9;
model GSL_SIGN
//This model calculates the sign of the number by calling the function GSL_SIGN(x)
parameter Real x = -4;
Integer y;
algorithm
y := gsl.mathematical.GSL_SIGN(x);
end GSL_SIGN;
model GSL_IS_ODD
//This model outputs 1 for odd number and 0 if the number is even by calling the function GSL_IS_ODD(x)
parameter Integer x = 2;
Real y(start = 0);
algorithm
y := gsl.mathematical.GSL_IS_ODD(x);
end GSL_IS_ODD;
model GSL_IS_EVEN
//This model outputs 1 for odd number and 0 if the number is even by calling the function GSL_IS_EVEN(x)
parameter Integer x = 2;
Real y;
algorithm
y := gsl.mathematical.GSL_IS_EVEN(x);
end GSL_IS_EVEN;
model GSL_MAX
//This model calls the function GSL_MAX(a,b) which return the maximum of a and b
parameter Real a = 1.0;
parameter Real b = 2.0;
Real c;
algorithm
c := gsl.mathematical.GSL_MAX(a, b);
end GSL_MAX;
model GSL_MAX_DBL
// This model gives the maximum of two double numbers by calling the function GSL_MAX_DBL
parameter Real a = 2.0;
parameter Real b = 3.0;
Real c;
algorithm
c := gsl.mathematical.GSL_MAX_DBL(a, b);
end GSL_MAX_DBL;
model GSL_MIN_DBL
// This model gives the minimum of two double numbers by calling the function GSL_MIN_DBL
parameter Real a = 2.0;
parameter Real b = 3.0;
Real c;
algorithm
c := gsl.mathematical.GSL_MIN_DBL(a, b);
end GSL_MIN_DBL;
model GSL_MAX_INT
// This model gives the maximum of two integers by calling the function GSL_MAX_INT
parameter Real a = 2;
parameter Real b = 3;
Real c;
algorithm
c := gsl.mathematical.GSL_MAX_INT(a, b);
end GSL_MAX_INT;
model GSL_MIN_INT
// This model gives the minimum of two integers by calling the function GSL_MIN_INT
parameter Real a = 2;
parameter Real b = 3;
Real c;
algorithm
c := gsl.mathematical.GSL_MIN_INT(a, b);
end GSL_MIN_INT;
model GSL_MAX_LDBL
// This model gives the maximum of two Real numbers by calling the function GSL_MAX_LDBL
parameter Real a = 2.00001;
parameter Real b = 3.00001;
Real c;
algorithm
c := gsl.mathematical.GSL_MAX_LDBL(a, b);
end GSL_MAX_LDBL;
model GSL_MIN_LDBL
// This model gives the minimum of two Real by calling the function GSL_MAX_DBL
parameter Real a = 2.00001;
parameter Real b = 3.00001;
Real c;
algorithm
c := gsl.mathematical.GSL_MIN_LDBL(a, b);
end GSL_MIN_LDBL;
model gsl_fcmp
//This model calls the function gsl_fcmp(a,b) and returns zero if they are equal in given range and -1 if a<b and +1 if a>b
parameter Real a = 4.0;
parameter Real b = 2.2;
Real c;
algorithm
c := gsl.mathematical.gsl_fcmp(a, b);
end gsl_fcmp;
/**/
end Mathematical;
package Permutation
/*this model initialise the permutation with 10 elements to {0,1,2,3,4,5,6,7,8,9}*/
//this model calls the function gsl_permutation_init(p) to initialize the permutation to {0,1,2,3,4,5,6,7,8,9}
//this model calls the function gsl_permutation_init(p) to initialize the permutation to {0,1,2,3,4,5,6,7,8,9}
//this model calls the function gsl_permutation_init(p) to initialize the permutation to {0,1,2,3,4,,
model gsl_per_init
/*this model initializes the permutation p to{0,1,2,3,4,5,6,7,8,9}*/
parameter Integer N = 10;
gsl.data_types.gsl_permutation p = gsl.data_types.gsl_permutation(N);
Integer y[10];
algorithm
gsl.Permutation.gsl_permutation_init(p);
for i in 1:10 loop
y[i] := gsl.Permutation.gsl_permutation_get(p, i - 1);
end for;
end gsl_per_init;
end Permutation;
package COMPLEX
end COMPLEX;
end Examples;
end gsl;
|