~wbetz/fesslix/flx_testing

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
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.

# basic arithmetic operations

default flxoutput::checktol = true;
default flxoutput::float::prec = 4;

calc 1000;
calc 0000.5000e-2;
calc 0000.5000;

calc 1e-5;
calc 1e5;
calc 0.5e5;
calc 0.5e-5;
calc ans;

calc !1; calc !0; calc !-5;
calc 16^0.5;
calc 2*4;
calc 16/0.5;
calc 1+2 { stream=cout; }; calc 1-2;
calc 2<=4; calc 2<=2; calc 2>2; calc 4<=2; calc 4>=2;
calc 2==2; calc 2!=2; calc 2==4; calc 2!=4;
calc 1&&1; calc 1&&0; calc 0&&0; calc 0&&1;
calc 1||1; calc 1||0; calc 0||0; calc 0||1;
calc 1?2:3; calc 0?2:3;

const c1 = 1+2+3;
calc c1;
const c2 = 2*c1+1;
calc c2;
var v2 = 2*c1+1;
var v3 = evalc(v2);
calc v2;
const c1 = 1;
calc c2;
calc v2;
calc v3;

calc pi;
calc e;
calc 180°-PI;
calc 77%;

# Some strange comment: äöqoüß?°dd
calc cos(pi);;;
calc sin(pi);
calc -sin(-pi/2);
calc evalr(sin(pi));
calc cos(evalc(pi));
calc evalc(sin(pi));
calc abs(-5.55);
calc arccos(0);
calc arcsin(0);
calc arccot(0.5);
calc arctan(0.5);
calc arctanh(0.5);
calc cdfn(0);
calc cdfn(0.5);
calc cosh(0);
calc cot(0.5);
calc exp(0.5);
calc factorial(6);
calc failLSF(0);
calc faillsf(0.01);
calc hvi(0);
calc hvi(0.01);
calc hvi(-0.01);
calc cdfn_inv(0.5);
calc cdfn_inv(0.4);
calc frac(pi);
calc round(pi);
calc round(pi,2);
calc round(3.5);
calc ln(1); calc ln(2);
calc log(1); calc log(2);
calc loga(2,2); calc loga(3,2);
calc pdfn(0); calc pdfn(5);
calc relidx(1e-3); calc relidx(1e-6);
calc sig(-42.3); calc sig(52.2);
calc sinh(0.5);
calc sqrt(9);
calc tan(0.5);
calc tanh(0.5);
calc 1+2+4^5;
calc binomialcoeff(5,3);
calc tgamma(1.5);
calc igamma(1.5,2);
#calc igammal(1.5,2);
calc sum(h99=1,h99<=5,h99+1,h99);
# beta-functions
  const alpha = 10;
  const beta = 1e9;
  const p = 0.99999;
  calc ibeta_inv(alpha,beta,p) {checkTOL=false;};;
  calc ibeta(alpha,beta,ans) {checkTOL=false;};;
  calc betafun(alpha,beta) {checkTOL=false;};;

calc optimize1D(x,[4,5],(x-2)*(x-3));
const x = 0;
calc root(x,[0,sqrt(2)],x-1,bisec);
calc root(x,[0,sqrt(2)],x-1,rgfsi);
calc root(x,[0,sqrt(2)],(x-1)^3,bisec);
calc root(x,[0,sqrt(2)],(x-1)^3,rgfsi);
calc root(x,[0,4*sqrt(2)],(x-1)^3-1,bisec,stream=cout);
calc root(x,[0,4*sqrt(2)],(x-1)^3-1,rgfsi,stream=cout);
calc x;

mtxconst_print tmpmtx!{ mtxconst_new tmpmtx = {49}; };
mtxconst_print tmpmtx!{ mtxconst_new tmpmtx = {1;2;3}; };   
mtxconst_print tmpmtx2!{ mtxconst_new tmpmtx2 = { 1, 2, 3; 4, 5, 6; 7, 8, 9 }; };
mtxconst_print tmpmtx2!{
  mtxconst_new tmpmtx3 = {1,2,3};
  mtxconst_mult tmpmtx2 = tmpmtx3*tmpmtx;
};
mtxconst_print tmpmtx!{ mtxconst_op tmpmtx += {tmpmtx}; };
mtxconst_new karl(4,1,2);
mtxconst_print karl;
echo "rows=" & { mtxrows(karl) } { newline=false; };
echo ", cols=" & { mtxcols(karl) };
mtxconst_print karlt!{
  mtxconst_new karlt({karl});
  mtxconst_transpose karlt;
};
echo "rows=" & { mtxrows(karlt) } & ", cols=" & { mtxcols(karlt) };
calc mtxsum(karlt);
calc vec_norm2(karlt);
mtxconst_free karlt;
mtxconst_new karl = {1;2;3;4;5};
mtxconst_op karl(i) = i^2;
mtxconst_print karl;
calc mtxprod(karl);
mtxconst_new karl = {1;2;3;4;5};
mtxconst_op karl += {karl};
mtxconst_op karl -= 1;
mtxconst_op karl /= 2;
mtxconst_print karl;
mtxconst_new karl = {33};
mtxconst_print karl;

mtxconst_print tmpmtx!{ mtxconst_new tmpmtx = seq(i=0,i<9.5,i+1); };
mtxconst_print tmpmtx!{ mtxconst_op tmpmtx ^= 2; };
mtxconst_print olaf!{
  mtxconst_new olaf = {1,5,8,99};
  mtxconst_op olaf(i)= sin(i);
};
calc mtxcoeff(olaf,0,1);
calc max({karl}, {olaf});
calc min({karl}, {olaf});
calc min(x, c1,c2,{karl},{olaf},v2,v3);
calc max(x, c1,c2,{karl},{olaf},v2,v3);
mtxconst_2octave Olaf;

fun f1(4) = $1+$2+$3+$4;
calc f1(1,2,3,4);

const x=1;
calc x;
sfor (i;10) {
  calc (integ(x=[0,pi],sin(x),gp=i)-2)/2;
};
calc x;

const x=0;
  const start=0;
  const end=20;
  var funI = 5*x^16+x^15-x^8+9*x-3;
const a = integ(x=[start,end],funI,gp=40);
calc a;
sfor (i;10) {
  funplot i, (integ(x=[start,end],funI,gp=i)-a)/a;
};
sfor (i;10;true) {
  funplot i, deg2gauss(i), i*pi {checkTOL=false;};
};

funplot 1e52;

mtxconst_new cv(5,1,0);
sfor (p;5) {
 sfor (M;5) {
  const np = 0;
  sfor (k;p;true) {
   const np = np + binomialcoeff(M+k-1,k);
  };
  mtxcoeff cv(M-1,0) = np;
 };
 funplot p,{cv} {checkTOL=false;};
};

mtxconst_print tmpmtx!{
  mtxconst_new tmpmtx = {1;2;3};
  mtxconst_new tmpmtx2 = {3;2;1};
  mtxconst_op tmpmtx *= {tmpmtx2};
};

catch_error {
  calc error(1);
};

echo {0.0123}$udef:"%4.2f";
echo {0.0123}$udef:"%4.2e";
echo {0.0123}$udef:"\t\\Some number %4.2e to be printed.";


# Plotting Legendre Polynomials
# =============================
filestream lp ( "output/test_1_lp.txt") ;
filter (j;tmpmtx!{ mtxconst_new tmpmtx = seq(j=-1,j<=1,j+0.1); } ) {
  funplot j, {tmpmtx2!{
    mtxconst_new tmpmtx2 = seq(i=1,i<=8,i+1);
    mtxconst_op tmpmtx2(i) = hlegendrepoly(i,j);
  }} {stream=lp;checkTOL=true;};
};

# Plotting Gegenbauer Polynomials
# =============================
filestream hgp ( "output/test_1_hgp.txt") ;
mtxconst_new tmpmtx2 = seq(i=1,i<=8,i+1);
filter (j;tmpmtx ) {
  funplot j, {tmpmtx3!{
    mtxconst_new tmpmtx3({tmpmtx2});
    mtxconst_op tmpmtx3(i) = hgegenbauerpoly(i,j);
  }} {stream=hgp;checkTOL=false;};
};

# Print the hierarchic Lengendre polynomials
# ==========================================
sfor(i;10) {
  print_hlegendrepoly(i){verbose=false;};
};


echo "integer=" & { PI*1000 }$int;



const c1 = rgammal(1.5,2);
const c2 = rgammal_inv(1.5,c1);
funplot c1, c2;

const c1 = cdf(4,gumbel,mu=5,sd=2);
const c2 = cdf_inv(c1,gumbel,mu=5,sd=2);
funplot c1, c2;

const c1 = cdf(4,gamma,mu=5,sd=2);
const c2 = cdf_inv(c1,gamma,mu=5,sd=2);
funplot c1, c2;

funplot p-0.99999,alpha,beta;
calc objexec(:c1,{const c2=2; const c1=c1+c2; const p=0; const alpha=0; const beta=0;}::{c2,p,alpha});
funplot p,alpha,beta, c1,c2;

# maximize entropy of a distirbution given constraints
const x =0;
const alpha = 2;
const pt = 0.1;
fun bf(1) = $1*(1-pt)/pt;
fun entr(1) = entropy(beta,alpha=$1,beta=bf($1));
funplot entr(1), entr(1.01), entr(1.1);
alp = Optimize1d(x,[0.001,10],-entr(x));
bet = bf(alp);
funplot pt, alp, bet, entr(alp);

calc rnd_y2x(0.4,beta,alpha=4,beta=9);



strconst alfons = "No comment";
echo $strconst(alfons);
strconst alfons = " not a single word!!!";
echo $strconst(alfons);
strconst alfons = "Alfons will say" & $strconst(alfons);
echo $strconst(alfons);
echo $substr($strconst(alfons),p:0,c:!);
echo $substr($strconst(alfons),c:w,s:" not");
echo $substr($strconst(alfons),c:w,l:4);
strconst numstr = "alf-5.334bernd";
funplot numberfromstring(numstr);
echo $strconst(numstr);

echo "-- start of loop";
for_each stri in ("alf,;bernd,;gustaf,;claus";",;") {
  echo $strconst(stri);
};
echo "-- end of loop";