File: dassldasrt.dia.ref

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (471 lines) | stat: -rw-r--r-- 13,980 bytes parent folder | download | duplicates (2)
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
 
// Copyright INRIA
 
//DASSL
 
// PROBLEM 1..   LINEAR DIFFERENTIAL/ALGEBRAIC SYSTEM
 
//
 
//X1DOT + 10.0*X1 = 0
 
//X1 + X2 = 1
 
//X1(0) = 1.0, X2(0) = 0.0
 
//
 
t=1:10;t0=0;y0=[1;0];y0d=[-10;0];
 
info=list([],0,[],[],[],0,0);
 
//    Calling Scilab functions
 
deff('[r,ires]=dres1(t,y,ydot)','r=[ydot(1)+10*y(1);y(2)+y(1)-1];ires=0')
 
deff('pd=djac1(t,y,ydot,cj)','pd=[cj+10,0;1,1]')
 
//   scilab function, without jacobian
 
yy0=dassl([y0,y0d],t0,t,dres1,info);
 
//   scilab functions, with jacobian
 
yy1=dassl([y0,y0d],t0,t,dres1,djac1,info);
 
// fortran routine, without jocabian
 
yy2=dassl([y0,y0d],t0,t,'dres1',info);   //=yy0
 
if norm(yy2-yy0,1)>1D-5 then bugmes();quit;end
 
// fortran routines, with jacobian
 
yy3=dassl([y0,y0d],t0,t,'dres1','djac1',info);  //=yy1
 
if norm(yy3-yy1,1)>1D-5 then bugmes();quit;end
 
yy3bis=dassl([y0,y0d],t0,t,'dres1',djac1,info);
 
// call fortran dres1 and scilab's djac1
 
yy3ter=dassl([y0,y0d],t0,t,dres1,'djac1',info);
 
//
 
// with specific atol and rtol parameters
 
atol=1.d-6;rtol=0;
 
yy4=dassl([y0,y0d],t0,t,atol,rtol,dres1,info);
 
yy5=dassl([y0,y0d],t0,t,atol,rtol,'dres1',info); //=yy4
 
if norm(yy5-yy4,1)>1D-9 then bugmes();quit;end
 
yy6=dassl([y0,y0d],t0,t,atol,rtol,dres1,djac1,info);
 
yy7=dassl([y0,y0d],t0,t,atol,rtol,'dres1','djac1',info); //==yy6
 
if norm(yy7-yy6,1)>1D-12 then bugmes();quit;end
 
//
 
//   Testing E xdot - A x=0
 
//   x(0)=x0;   xdot(0)=xd0
 
rand('seed',0);
 
nx=5;
 
E=rand(nx,1)*rand(1,nx);A=rand(nx,nx);
 
//         Index 1
 
[Si,Pi,Di,o]=penlaur(E,A);pp=Si*E;[q,m]=fullrf(pp);x0=q(:,1);x0d=pinv(E)*A*x0;
    rank A^k    rcond
        1.      0.100D+01
 
deff('[r,ires]=g(t,x,xdot)','r=E*xdot-A*x;ires=0');
 
t=[1,2,3];t0=0;info=list([],0,[],[],[],0,0);
 
x=dassl([x0,x0d],t0,t,g,info);x1=x(2:nx+1,:);
 
if norm(pp*x1-x1,1)>1.d-5 then bugmes();quit;end
 
//x(4) goes through 1 at  t=1.5409711;
 
t=1.5409711;ww=dassl([x0,x0d],t0,t,g,info);
 
if abs(ww(5)-1)>0.001 then bugmes();quit;end
 
deff('[rt]=surface(t,y,yd)','rt=y(4)-1');nbsurf=1;
 
[yyy,nnn]=dasrt([x0,x0d],t0,t,g,nbsurf,surface,info);
 
deff('pd=j(t,y,ydot,cj)','pd=cj*D-A');
 
x=dassl([x0,x0d],t0,t,g,j,info);x2=x(2:nx+1,1);
 
if norm(x2-ww(2:nx+1,1),1)>0.0001 then bugmes();quit;end
 
[yyy1,nnn]=dasrt([x0,x0d],t0,t,g,j,nbsurf,surface,info);
 
//x0d is not known:
 
x0d=ones(x0);info(7)=1;
 
x=dassl([x0,x0d],t0,t,g,info);
 
xn=dassl([x0,x0d],t0,t,g,j,info);
 
if norm(x-xn,1)>0.00001 then bugmes();quit;end
 
 
 
//PROBLEM 2..
 
 
info=list([],0,[],[],[],0,0);
 
y0=zeros(25,1);y0(1)=1;
 
delta=0*y0;
 
//link('dres2.o','dres2');
 
//y0d=call('dres2',0,1,'d',y0,2,'d',delta,3,'d',0,5,'i',0,6,'d',0,7,'d','out',[25,1],4,'d');
 
y0d=zeros(y0);y0d(1)=-2;y0d(2)=1;y0d(6)=1;
 
t0=0;t=[0.01,0.1,1,10,100];
 
rtol=0;atol=1.d-6;
 
y=dassl([y0,y0d],t0,t,atol,rtol,'dres2',info);
 
 
//                 DASRT
 
//
 
//C-----------------------------------------------------------------------
 
//C First problem.
 
//C The initial value problem is..
 
//C   DY/DT = ((2*LOG(Y) + 8)/T - 5)*Y,  Y(1) = 1,  10.LE. T0.LE. 6
 
//C The solution is  Y(T) = EXP(-T**2 + 5*T - 4), YPRIME(1) = 3
 
//C The two root functions are..
 
//C   G1 = ((2*LOG(Y)+8)/T - 5)*Y (= DY/DT)  (with root at T = 2.5),
 
//C   G2 = LOG(Y) - 2.2491  (with roots at T = 2.47 and 2.53)
 
//C-----------------------------------------------------------------------
 
y0=1;t=2:6;t0=1;y0d=3;
 
info=list([],0,[],[],[],0,0);
 
atol=1.d-6;rtol=0;ng=2;
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,'res1',ng,'gr1',info);
 
if abs(nn(1)-2.47)>0.001 then bugmes();quit;end
 
y0=yy(2,2);y0d=yy(3,2);t0=nn(1);t=[3,4,5,6];
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,'res1',ng,'gr1',info);
 
if abs(nn(1)-2.5)>0.001 then bugmes();quit;end
 
y0=yy(2,1);y0d=yy(3,1);t0=nn(1);t=[3,4,5,6];
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,'res1',ng,'gr1',info);
 
if abs(nn(1)-2.53)>0.001 then bugmes();quit;end
 
 
deff('[delta,ires]=res1(t,y,ydot)','ires=0;delta=ydot-((2*log(y)+8)/t-5)*y')
 
deff('[rts]=gr1(t,y,yd)','rts=[((2*log(y)+8)/t-5)*y;log(y)-2.2491]')
 
 
y0=1;t=2:6;t0=1;y0d=3;
 
info=list([],0,[],[],[],0,0);
 
atol=1.d-6;rtol=0;ng=2;
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res1,ng,gr1,info);
 
if abs(nn(1)-2.47)>0.001 then bugmes();quit;end
 
y0=yy(2,2);y0d=yy(3,2);t0=nn(1);t=[3,4,5,6];
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res1,ng,gr1,info);
 
if abs(nn(1)-2.5)>0.001 then bugmes();quit;end
 
y0=yy(2,1);y0d=yy(3,1);t0=nn(1);t=[3,4,5,6];
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res1,ng,gr1,info);
 
if abs(nn(1)-2.53)>0.001 then bugmes();quit;end
 
 
//C
 
//C-----------------------------------------------------------------------
 
//C Second problem (Van Der Pol oscillator).
 
//C The initial value problem is..
 
//C   DY1/DT = Y2,  DY2/DT = 100*(1 - Y1**2)*Y2 - Y1,
 
//C   Y1(0) = 2,  Y2(0) = 0,  00.LE. T0.LE. 200
 
//C   Y1PRIME(0) = 0, Y2PRIME(0) = -2
 
//C The root function is  G = Y1.
 
//C An analytic solution is not known, but the zeros of Y1 are known
 
//C to 15 figures for purposes of checking the accuracy.
 
//C-----------------------------------------------------------------------
 
rtol=[1.d-6;1.d-6];atol=[1.d-6;1.d-4];
 
t0=0;y0=[2;0];y0d=[0;-2];t=[20:20:200];ng=1;
 
info=list([],0,[],[],[],0,0);
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,'res2','jac2',ng,'gr2',info);
 
if abs(nn(1)-81.163512)>0.001 then bugmes();quit;end
 
 
deff('[delta,ires]=res2(t,y,ydot)',...
'ires=0;y1=y(1),y2=y(2),delta=[ydot-[y2;100*(1-y1*y1)*y2-y1]]')
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res2,'jac2',ng,'gr2',info);
 
deff('J=jac2(t,y,ydot,c)','y1=y(1);y2=y(2);J=[c,-1;200*y1*y2+1,c-100*(1-y1*y1)]')
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res2,jac2,ng,'gr2',info);
 
deff('s=gr2(t,y,yd)','s=y(1)')
 
[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,res2,jac2,ng,gr2,info);
 
 
//           Hot Restart
 
 
[yy,nn,hotd]=dasrt([y0,y0d],t0,t,atol,rtol,'res2','jac2',ng,'gr2',info);
 
t01=nn(1);t=100:20:200;[pp,qq]=size(yy);y01=yy(2:3,qq);y0d1=yy(3:4,qq);
 
[yy,nn,hotd]=dasrt([y01,y0d1],t01,t,atol,rtol,'res2','jac2',ng,'gr2',info,hotd);
 
if abs(nn(1)-162.57763)>0.001 then bugmes();quit;end
 
 
//Test of Dynamic link (Require f77!)
 
//         1 making the routines
 
res22=[...
'      SUBROUTINE RES22(T,Y,YDOT,DELTA,IRES,RPAR,IPAR)';
'      IMPLICIT DOUBLE PRECISION (A-H,O-Z)';
'      INTEGER NEQ';
'      DIMENSION Y(*), YDOT(*), DELTA(*)';
'      NEQ=2';
'      CALL F2(NEQ,T,Y,DELTA)';
'      DO 10 I = 1,NEQ';
'         DELTA(I) = YDOT(I) - DELTA(I)';
' 10   CONTINUE';
'      RETURN';
'      END';
'      SUBROUTINE F2 (NEQ, T, Y, YDOT)';
'      IMPLICIT DOUBLE PRECISION (A-H,O-Z)';
'      INTEGER NEQ';
'      DOUBLE PRECISION T, Y, YDOT';
'      DIMENSION Y(*), YDOT(*)';
'      YDOT(1) = Y(2)';
'      YDOT(2) = 100.0D0*(1.0D0 - Y(1)*Y(1))*Y(2) - Y(1)';
'      RETURN';
'      END';]
 res22  =
 
!      SUBROUTINE RES22(T,Y,YDOT,DELTA,IRES,RPAR,IPAR)    !
!                                                         !
!      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                !
!                                                         !
!      INTEGER NEQ                                        !
!                                                         !
!      DIMENSION Y(*), YDOT(*), DELTA(*)                  !
!                                                         !
!      NEQ=2                                              !
!                                                         !
!      CALL F2(NEQ,T,Y,DELTA)                             !
!                                                         !
!      DO 10 I = 1,NEQ                                    !
!                                                         !
!         DELTA(I) = YDOT(I) - DELTA(I)                   !
!                                                         !
! 10   CONTINUE                                           !
!                                                         !
!      RETURN                                             !
!                                                         !
!      END                                                !
!                                                         !
!      SUBROUTINE F2 (NEQ, T, Y, YDOT)                    !
!                                                         !
!      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                !
!                                                         !
!      INTEGER NEQ                                        !
!                                                         !
!      DOUBLE PRECISION T, Y, YDOT                        !
!                                                         !
!      DIMENSION Y(*), YDOT(*)                            !
!                                                         !
!      YDOT(1) = Y(2)                                     !
!                                                         !
!      YDOT(2) = 100.0D0*(1.0D0 - Y(1)*Y(1))*Y(2) - Y(1)  !
!                                                         !
!      RETURN                                             !
!                                                         !
!      END                                                !
 
 
jac22=[...
'      SUBROUTINE JAC22 (T, Y, ydot, PD, CJ, RPAR, IPAR)';
' ';
'      IMPLICIT DOUBLE PRECISION (A-H,O-Z)';
'      INTEGER  NROWPD';
'      DOUBLE PRECISION T, Y, PD';
'      PARAMETER (NROWPD=2)';
'      DIMENSION Y(2), PD(NROWPD,2)';
'      PD(1,1) = 0.0D0';
'      PD(1,2) = 1.0D0';
'      PD(2,1) = -200.0D0*Y(1)*Y(2) - 1.0D0';
'      PD(2,2) = 100.0D0*(1.0D0 - Y(1)*Y(1))';
'      PD(1,1) = CJ - PD(1,1)';
'      PD(1,2) =    - PD(1,2)';
'      PD(2,1) =    - PD(2,1)';
'      PD(2,2) = CJ - PD(2,2)';
'      RETURN';
'      END';]
 jac22  =
 
!      SUBROUTINE JAC22 (T, Y, ydot, PD, CJ, RPAR, IPAR)  !
!                                                         !
!                                                         !
!                                                         !
!      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                !
!                                                         !
!      INTEGER  NROWPD                                    !
!                                                         !
!      DOUBLE PRECISION T, Y, PD                          !
!                                                         !
!      PARAMETER (NROWPD=2)                               !
!                                                         !
!      DIMENSION Y(2), PD(NROWPD,2)                       !
!                                                         !
!      PD(1,1) = 0.0D0                                    !
!                                                         !
!      PD(1,2) = 1.0D0                                    !
!                                                         !
!      PD(2,1) = -200.0D0*Y(1)*Y(2) - 1.0D0               !
!                                                         !
!      PD(2,2) = 100.0D0*(1.0D0 - Y(1)*Y(1))              !
!                                                         !
!      PD(1,1) = CJ - PD(1,1)                             !
!                                                         !
!      PD(1,2) =    - PD(1,2)                             !
!                                                         !
!      PD(2,1) =    - PD(2,1)                             !
!                                                         !
!      PD(2,2) = CJ - PD(2,2)                             !
!                                                         !
!      RETURN                                             !
!                                                         !
!      END                                                !
 
 
 
gr22=[...
'      SUBROUTINE GR22 (NEQ, T, Y, NG, GROOT, RPAR, IPAR)';
'      IMPLICIT DOUBLE PRECISION (A-H,O-Z)';
'      INTEGER NEQ, NG';
'      DOUBLE PRECISION T, Y, GROOT';
'      DIMENSION Y(*), GROOT(*)';
'      GROOT(1) = Y(1)';
'      RETURN';
'      END';]
 gr22  =
 
!      SUBROUTINE GR22 (NEQ, T, Y, NG, GROOT, RPAR, IPAR)  !
!                                                          !
!      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                 !
!                                                          !
!      INTEGER NEQ, NG                                     !
!                                                          !
!      DOUBLE PRECISION T, Y, GROOT                        !
!                                                          !
!      DIMENSION Y(*), GROOT(*)                            !
!                                                          !
!      GROOT(1) = Y(1)                                     !
!                                                          !
!      RETURN                                              !
!                                                          !
!      END                                                 !
 
 
//Uncomment lines below: link may be machine dependent if some f77 libs are
 
//needed for linking
 
//unix_g('cd /tmp;rm -f /tmp/res22.f');unix_g('cd /tmp;rm -f /tmp/gr22.f');
 
//unix_g('cd /tmp;rm -f /tmp/jac22.f');
 
//write('/tmp/res22.f',res22);write('/tmp/gr22.f',gr22);write('/tmp/jac22.f',jac22)
 
//unix_g("cd /tmp;make /tmp/res22.o");unix_g('cd /tmp;make /tmp/gr22.o');
 
//unix_g('cd /tmp;make /tmp/jac22.o');
 
//          2  Linking the routines
 
//link('/tmp/res22.o','res22');link('/tmp/jac22.o','jac22');link('/tmp/gr22.o','gr22')
 
//rtol=[1.d-6;1.d-6];atol=[1.d-6;1.d-4];
 
//t0=0;y0=[2;0];y0d=[0;-2];t=[20:20:200];ng=1;
 
//info=list([],0,[],[],[],0,0);
 
//          3 Calling the routines by dasrt
 
//[yy,nn]=dasrt([y0,y0d],t0,t,atol,rtol,'res22','jac22',ng,'gr22',info);
 
// hot restart
 
//[yy,nn,hotd]=dasrt([y0,y0d],t0,t,atol,rtol,'res22','jac22',ng,'gr22',info);
 
//t01=nn(1);t=100:20:200;[pp,qq]=size(yy);y01=yy(2:3,qq);y0d1=yy(3:4,qq);
 
//[yy,nn,hotd]=dasrt([y01,y0d1],t01,t,atol,rtol,'res22','jac22',ng,'gr22',info,hotd);