Last change
on this file since 882 was 850, checked in by ansari, 25 years ago |
Corrections divers + RansomSequence - Reza 10/4/2000
|
File size:
1.5 KB
|
Line | |
---|
1 | // Utility classes for template numerical arrays
|
---|
2 | // R. Ansari, C.Magneville 03/2000
|
---|
3 |
|
---|
4 | #include "machdefs.h"
|
---|
5 | #include "utilarr.h"
|
---|
6 | #include "srandgen.h"
|
---|
7 |
|
---|
8 | // Classe utilitaires
|
---|
9 |
|
---|
10 | RandomSequence::RandomSequence(int typ, double m, double s)
|
---|
11 | {
|
---|
12 | typ_ = (typ == Flat) ? Flat : Gaussian;
|
---|
13 | mean_ = m;
|
---|
14 | sig_ = s;
|
---|
15 | }
|
---|
16 |
|
---|
17 | double RandomSequence::Rand()
|
---|
18 | {
|
---|
19 | if (typ_ == Flat)
|
---|
20 | return(drandpm1()*sig_ + mean_);
|
---|
21 | else return(GauRnd(mean_, sig_));
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f)
|
---|
26 | : rseq_(RandomSequence::Gaussian)
|
---|
27 | {
|
---|
28 | start_ = start;
|
---|
29 | step_ = step;
|
---|
30 | myf_ = f;
|
---|
31 | fgrseq_ = false;
|
---|
32 | }
|
---|
33 |
|
---|
34 | Sequence::Sequence(RandomSequence rseq)
|
---|
35 | {
|
---|
36 | start_ = 0.;
|
---|
37 | step_ = 1.;
|
---|
38 | myf_ = NULL;
|
---|
39 | rseq_ = rseq;
|
---|
40 | fgrseq_ = true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | double Sequence::operator () (uint_4 k)
|
---|
44 | {
|
---|
45 | if (fgrseq_) return(rseq_.Rand());
|
---|
46 | else {
|
---|
47 | double x = start_+(double)k*step_;
|
---|
48 | if (myf_) return(myf_(x));
|
---|
49 | else return x;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | Range::Range(uint_4 start, uint_4 end, uint_4 size, uint_4 step)
|
---|
54 | {
|
---|
55 | start_ = start;
|
---|
56 | step_ = (step > 0) ? step : 1;
|
---|
57 | if (end > start) { // Taille calcule automatiquement
|
---|
58 | end_ = end;
|
---|
59 | if (step_ > ((end_-start_)+1)) size_ = 1;
|
---|
60 | else size_ = ((end-start)+1)/step_;
|
---|
61 | }
|
---|
62 | else { // Taille fixee
|
---|
63 | size_ = size;
|
---|
64 | end_ = start_+size_*step_;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | /*
|
---|
69 | Range & Range::operator = (uint_4 start)
|
---|
70 | {
|
---|
71 | start_ = start;
|
---|
72 | size_ = 1;
|
---|
73 | step_ = 1;
|
---|
74 | return (*this);
|
---|
75 | }
|
---|
76 | */
|
---|
77 |
|
---|
78 |
|
---|
79 | IdentityMatrix::IdentityMatrix(double diag, uint_4 n)
|
---|
80 | {
|
---|
81 | size_ = n;
|
---|
82 | diag_ = diag;
|
---|
83 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.