-
Notifications
You must be signed in to change notification settings - Fork 0
/
ode.cpp
1686 lines (1601 loc) · 39.6 KB
/
ode.cpp
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <cmath>
# include <cstdlib>
# include <iostream>
# include <fstream>
# include <iomanip>
# include <ctime>
using namespace std;
# include "ode.hpp"
//****************************************************************************80
void de
(
const odefun& f,
int neqn,
double y[],
double &t,
double tout,
double relerr,
double abserr,
int &iflag,
double yy[],
double wt[],
double p[],
double yp[],
double ypout[],
double phi[],
double alpha[],
double beta[],
double sig[],
double v[],
double w[],
double g[],
bool &phase1,
double psi[],
double &x,
double &h,
double &hold,
bool &start,
double &told,
double &delsgn,
int &ns,
bool &nornd,
int &k,
int &kold,
int &isnold
)
//****************************************************************************80
//
// Purpose:
//
// DE carries out the ODE solution algorithm.
//
// Discussion:
//
// ODE merely allocates storage for DE, to relieve the user of the
// inconvenience of a long call list. Consequently, DE is used as
// described in the comments for ODE.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 February 2021
//
// Author:
//
// Original FORTRAN77 version by Lawrence Shampine, Marilyn Gordon.
// C++ version by John Burkardt.
// Modified by Zvonimir Stojanovski.
//
// Reference:
//
// Lawrence Shampine, Marilyn Gordon,
// Computer Solution of Ordinary Differential Equations:
// The Initial Value Problem,
// Freeman, 1975,
// ISBN: 0716704617,
// LC: QA372.S416.
//
// Parameters:
//
// Input, void F ( double T, double Y[], double YP[] ), the user-supplied function
// which accepts input values T and Y[], evaluates the right hand
// sides of the ODE, and stores the result in YP[].
//
// Input, int NEQN, the number of equations.
//
// Input/output, double Y[NEQN], the current solution.
//
// Input/output, double &T, the current value of the independent
// variable.
//
// Input, double TOUT, the desired value of T on output.
//
// Input, double RELERR, ABSERR, the relative and absolute error
// tolerances. At each step, the code requires
// abs ( local error ) <= abs ( Y ) * RELERR + ABSERR
// for each component of the local error and solution vectors.
//
// Input/output, int &IFLAG, indicates the status of integration.
// On input, IFLAG is normally 1 (or -1 in the special case where TOUT is
// not to be exceeded.) On normal output, IFLAG is 2. Other output values
// are:
// * 3, integration did not reach TOUT because the error tolerances were
// too small.
// But RELERR and ABSERR were increased appropriately for continuing;
// * 4, integration did not reach TOUT because more than 500 steps were taken;
// * 5, integration did not reach TOUT because the equations appear to be
// stiff;
// * 6, invalid input parameters (fatal error).
// The value of IFLAG is returned negative when the input value is negative
// and the integration does not reach TOUT.
//
// Workspace, double YY[NEQN], used to hold old solution data.
//
// Input, double WT[NEQN], the error weight vector.
//
// Workspace, double P[NEQN].
//
// Workspace, double YP[NEQN], used to hold values of the
// solution derivative.
//
// Workspace, double YPOUT[NEQN], used to hold values of the
// solution derivative.
//
// Workspace, double PHI[NEQN*16], contains divided difference
// information about the polynomial interpolant to the solution.
//
// Workspace, double ALPHA[12], BETA[12], SIG[13].
//
// Workspace, double V[12], W[12], G[13].
//
// Input/output, bool &PHASE1, indicates whether the program is in the
// first phase, when it always wants to increase the ODE method order.
//
// Workspace, double PSI[12], contains information about
// the polynomial interpolant to the solution.
//
// Input/output, double &X, a "working copy" of T, the current value
// of the independent variable, which is adjusted as the code attempts
// to take a step.
//
// Input/output, double &H, the current stepsize.
//
// Input/output, double &HOLD, the last successful stepsize.
//
// Input/output, bool &START, is TRUE on input for the first step.
// The program initializes data, and sets START to FALSE.
//
// Input/output, double &TOLD, the previous value of T.
//
// Input/output, double &DELSGN, the sign (+1 or -1) of TOUT - T.
//
// Input/output, int &NS, the number of steps taken with stepsize H.
//
// Input/output, bool &NORND, ?
//
// Input/output, int &K, the order of the current ODE method.
//
// Input/output, int &KOLD, the order of the ODE method on the previous step.
//
// Input/output, int &ISNOLD, the previous value of ISN, the sign
// of IFLAG.
//
// Local parameters:
//
// Local, integer MAXNUM, the maximum number of steps allowed in one
// call to DE.
//
{
double absdel;
double abseps;
bool crash;
double del;
double eps;
double fouru;
int isn;
int kle4;
int l;
const int maxnum = 500;
int nostep;
double releps;
bool stiff;
double tend;
//
// Test for improper parameters.
//
fouru = 4.0 * r8_epsilon ( );
if ( neqn < 1 )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " NEQN < 1.\n";
exit ( 1 );
}
if ( t == tout )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " T = TOUT.\n";
exit ( 1 );
}
if ( relerr < 0.0 || abserr < 0.0 )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " RELERR < 0 or ABSERR < 0.\n";
exit ( 1 );
}
eps = r8_max ( relerr, abserr );
if ( eps <= 0.0 )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " max ( RELERR, ABSERR ) <= 0.\n";
exit ( 1 );
}
if ( iflag == 0 )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " IFLAG = 0 on input.\n";
exit ( 1 );
}
isn = i4_sign ( iflag );
iflag = abs ( iflag );
if ( iflag != 1 )
{
if ( t != told )
{
iflag = 6;
cerr << "\n";
cerr << "DE - Fatal error!\n";
cerr << " IFLAG is not 1, and T is not equal to TOLD.\n";
exit ( 1 );
}
if ( iflag < 2 || 5 < iflag )
{
iflag = 6;
return;
}
}
//
// On each call set interval of integration and counter for number of
// steps. Adjust input error tolerances to define weight vector for
// subroutine STEP.
//
del = tout - t;
absdel = fabs ( del );
if ( isn < 0 )
{
tend = tout;
}
else
{
tend = t + 10.0 * del;
}
nostep = 0;
kle4 = 0;
stiff = false;
releps = relerr / eps;
abseps = abserr / eps;
//
// On start and restart, also set work variables X and YY(*), store the
// direction of integration, and initialize the step size.
//
if ( iflag == 1 || isnold < 0 || delsgn * del <= 0.0 )
{
start = true;
x = t;
for ( l = 1; l <= neqn; l++ )
{
yy[l-1] = y[l-1];
}
delsgn = r8_sign ( del );
h = r8_max ( fabs ( tout - x ), fouru * fabs ( x ) ) * r8_sign ( tout - x );
}
//
// If already past the output point, then interpolate and return.
//
for ( ; ; )
{
if ( absdel <= fabs ( x - t ) )
{
intrp ( x, yy, tout, y, ypout, neqn, kold, phi, psi );
iflag = 2;
t = tout;
told = t;
isnold = isn;
break;
}
//
// If we cannot go past the output point, and we are sufficiently
// close to it, then extrapolate and return.
//
if ( isn <= 0 && fabs ( tout - x ) < fouru * fabs ( x ) )
{
h = tout - x;
f ( x, yy, yp );
for ( l = 1; l <= neqn; l++ )
{
y[l-1] = yy[l-1] + h * yp[l-1];
}
iflag = 2;
t = tout;
told = t;
isnold = isn;
break;
}
//
// Test for too many steps.
//
if ( maxnum <= nostep )
{
iflag = isn * 4;
if ( stiff )
{
iflag = isn * 5;
}
for ( l = 1; l <= neqn; l++ )
{
y[l-1] = yy[l-1];
}
t = x;
told = t;
isnold = 1;
break;
}
//
// Limit the step size, set the weight vector and take a step.
//
h = r8_min ( fabs ( h ), fabs ( tend - x ) ) * r8_sign ( h );
for ( l = 1; l <= neqn; l++ )
{
wt[l-1] = releps * fabs ( yy[l-1] ) + abseps;
}
step ( x, yy, f, neqn, h, eps, wt, start,
hold, k, kold, crash, phi, p, yp, psi,
alpha, beta, sig, v, w, g, phase1, ns, nornd );
//
// Test for tolerances too small.
//
if ( crash )
{
iflag = isn * 3;
relerr = eps * releps;
abserr = eps * abseps;
for ( l = 1; l <= neqn; l++ )
{
y[l-1] = yy[l-1];
}
t = x;
told = t;
isnold = 1;
break;
}
//
// Augment the step counter and test for stiffness.
//
nostep = nostep + 1;
kle4 = kle4 + 1;
if ( 4 < kold )
{
kle4 = 0;
}
if ( 50 <= kle4 )
{
stiff = true;
}
}
return;
}
//****************************************************************************80
int i4_sign ( int i )
//****************************************************************************80
//
// Purpose:
//
// I4_SIGN returns the sign of an I4.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 27 March 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int I, the integer whose sign is desired.
//
// Output, int I4_SIGN, the sign of I.
{
int value;
if ( i < 0 )
{
value = -1;
}
else
{
value = 1;
}
return value;
}
//****************************************************************************80
void intrp
(
double x,
double y[],
double xout,
double yout[],
double ypout[],
int neqn,
int kold,
double phi[],
double psi[]
)
//****************************************************************************80
//
// Purpose:
//
// INTRP approximates the solution at XOUT by polynomial interpolation.
//
// Discussion:
//
// The methods in STEP approximate the solution near X by a polynomial.
// This routine approximates the solution at XOUT by evaluating the
// polynomial there. Information defining this polynomial is passed
// from STEP, so INTRP cannot be used alone.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 15 January 2012
//
// Author:
//
// Original FORTRAN77 version by Lawrence Shampine, Marilyn Gordon.
// C++ version by John Burkardt.
//
// Reference:
//
// Lawrence Shampine, Marilyn Gordon,
// Computer Solution of Ordinary Differential Equations:
// The Initial Value Problem,
// Freeman, 1975,
// ISBN: 0716704617,
// LC: QA372.S416.
//
// Parameters:
//
// Input, double X, the point where the solution has been computed.
//
// Input, double Y[NEQN], the computed solution at X.
//
// Input, double XOUT, the point at which the solution is desired.
//
// Output, double YOUT[NEQN], the solution at XOUT.
//
// Output, double YPOUT[NEQN], the derivative of the solution
// at XOUT.
//
// Input, int NEQN, the number of equations.
//
// Input, int KOLD, the order used for the last
// successful step.
//
// Input, double PHI[NEQN*16], contains information about the
// interpolating polynomial.
//
// Input, double PSI[12], contains information about the
// interpolating polynomial.
//
{
double eta;
double g[13];
double gamma;
double hi;
int i;
int j;
int k;
int ki;
double psijm1;
double rho[13];
double term;
double w[13];
hi = xout - x;
ki = kold + 1;
//
// Initialize W for computing G.
//
for ( i = 1; i <= ki; i++ )
{
w[i-1] = 1.0 / ( double ) ( i );
}
//
// Compute G.
//
g[0] = 1.0;
rho[0] = 1.0;
term = 0.0;
for ( j = 2; j <= ki; j++ )
{
psijm1 = psi[j-2];
gamma = ( hi + term ) / psijm1;
eta = hi / psijm1;
for ( i = 1; i <= ki + 1 - j; i++ )
{
w[i-1] = gamma * w[i-1] - eta * w[i];
}
g[j-1] = w[0];
rho[j-1] = gamma * rho[j-2];
term = psijm1;
}
//
// Interpolate.
//
for ( k = 0; k < neqn; k++ )
{
ypout[k] = 0.0;
yout[k] = 0.0;
}
for ( j = 1; j <= ki; j++ )
{
i = ki + 1 - j;
for ( k = 0; k < neqn; k++ )
{
yout[k] = yout[k] + g[i-1] * phi[k+(i-1)*neqn];
ypout[k] = ypout[k] + rho[i-1] * phi[k+(i-1)*neqn];
}
}
for ( k = 0; k < neqn; k++ )
{
yout[k] = y[k] + hi * yout[k];
}
return;
}
//****************************************************************************80
void ode
(
const odefun& f,
int neqn,
double y[],
double &t,
double tout,
double relerr,
double abserr,
int &iflag,
double work[],
int iwork[]
)
//****************************************************************************80
//
// Purpose:
//
// ODE is the user interface to an ordinary differential equation solver.
//
// Discussion:
//
// ODE integrates a system of NEQN first order ordinary differential
// equations of the form:
// dY(i)/dT = F(T,Y(1),Y(2),...,Y(NEQN))
// Y(i) given at T.
// The subroutine integrates from T to TOUT. On return, the
// parameters in the call list are set for continuing the integration.
// The user has only to define a new value TOUT and call ODE again.
//
// The differential equations are actually solved by a suite of codes
// DE, STEP, and INTRP. ODE allocates virtual storage in the
// arrays WORK and IWORK and calls DE. DE is a supervisor which
// directs the solution. It calls the routines STEP and INTRP
// to advance the integration and to interpolate at output points.
//
// STEP uses a modified divided difference form of the Adams PECE
// formulas and local extrapolation. It adjusts the order and step
// size to control the local error per unit step in a generalized
// sense. Normally each call to STEP advances the solution one step
// in the direction of TOUT. For reasons of efficiency, DE integrates
// beyond TOUT internally, though never beyond T+10*(TOUT-T), and
// calls INTRP to interpolate the solution at TOUT. An option is
// provided to stop the integration at TOUT but it should be used
// only if it is impossible to continue the integration beyond TOUT.
//
// On the first call to ODE, the user must provide storage in the calling
// program for the arrays in the call list,
// Y(NEQN), WORK(100+21*NEQN), IWORK(5),
// declare F in an external statement, supply the double precision
// SUBROUTINE F ( T, Y, YP )
// to evaluate dy(i)/dt = yp(i) = f(t,y(1),y(2),...,y(neqn))
// and initialize the parameters:
// * NEQN, the number of equations to be integrated;
// * Y(1:NEQN), the vector of initial conditions;
// * T, the starting point of integration;
// * TOUT, the point at which a solution is desired;
// * RELERR, ABSERR, the relative and absolute local error tolerances;
// * IFLAG, an indicator to initialize the code. Normal input
// is +1. The user should set IFLAG = -1 only if it is
// impossible to continue the integration beyond TOUT.
// All parameters except F, NEQN and TOUT may be altered by the
// code on output, and so must be variables in the calling program.
//
// On normal return from ODE, IFLAG is 2, indicating that T has been
// set to TOUT, and Y has been set to the approximate solution at TOUT.
//
// If IFLAG is 3, then the program noticed that RELERR or ABSERR was
// too small; the output values of these variables are more appropriate,
// and integration can be resumed by setting IFLAG to 1.
//
// IFLAG is -2 if the user input IFLAG = -1, and the code was able to
// reach TOUT exactly. In that case, the output value of T is TOUT,
// and the output value of Y is the solution at TOUT, which was computed
// directly, and not by interpolation.
//
// Other values of IFLAG generally indicate an error.
//
// Normally, it is desirable to compute many points along the solution
// curve. After the first successful step, more steps may be taken
// simply by updating the value of TOUT and calling ODE again.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 February 2021
//
// Author:
//
// Original FORTRAN77 version by Lawrence Shampine, Marilyn Gordon.
// C++ version by John Burkardt.
// Modified by Zvonimir Stojanovski.
//
// Reference:
//
// Lawrence Shampine, Marilyn Gordon,
// Computer Solution of Ordinary Differential Equations:
// The Initial Value Problem,
// Freeman, 1975,
// ISBN: 0716704617,
// LC: QA372.S416.
//
// Parameters:
//
// Input, void F ( double T, double Y[], double YP[] ), the user-supplied function
// which accepts input values T and Y[], evaluates the right hand
// sides of the ODE, and stores the result in YP[].
//
// Input, int NEQN, the number of equations.
//
// Input/output, double Y[NEQN], the current solution.
//
// Input/output, double &T, the current value of the independent
// variable.
//
// Input, double TOUT, the desired value of T on output.
//
// Input, double RELERR, ABSERR, the relative and absolute error
// tolerances. At each step, the code requires
// abs ( local error ) <= abs ( y ) * relerr + abserr
// for each component of the local error and solution vectors.
//
// Input/output, int &IFLAG, indicates the status of integration.
// On input, IFLAG is normally 1 (or -1 in the special case where TOUT is
// not to be exceeded.) On normal output, IFLAG is 2. Other output values
// are:
// * 3, integration did not reach TOUT because the error tolerances
// were too small. But RELERR and ABSERR were increased appropriately
// for continuing;
// * 4, integration did not reach TOUT because more than 500 steps were taken;
// * 5, integration did not reach TOUT because the equations appear to
// be stiff;
// * 6, invalid input parameters (fatal error).
// The value of IFLAG is returned negative when the input value is
// negative and the integration does not reach TOUT.
//
// Input/output, double WORK[100+21*NEQN], workspace.
//
// Input/output, int IWORK[5], workspace.
//
{
const int ialpha = 1;
const int ibeta = 13;
const int idelsn = 93;
const int ig = 62;
const int ih = 89;
const int ihold = 90;
int ip;
const int iphase = 75;
int iphi;
const int ipsi = 76;
const int isig = 25;
const int istart = 91;
const int itold = 92;
const int iv = 38;
const int iw = 50;
int iwt;
const int ix = 88;
int iyp;
int iypout;
const int iyy = 100;
bool nornd;
bool phase1;
bool start;
iwt = iyy + neqn;
ip = iwt + neqn;
iyp = ip + neqn;
iypout = iyp + neqn;
iphi = iypout + neqn;
if ( abs ( iflag ) != 1 )
{
start = ( 0.0 < work[istart-1] );
phase1 = ( 0.0 < work[iphase-1] );
nornd = ( iwork[1] != -1 );
}
de ( f, neqn, y, t, tout, relerr, abserr, iflag, work+iyy-1,
work+iwt-1, work+ip-1, work+iyp-1, work+iypout-1, work+iphi-1,
work+ialpha-1, work+ibeta-1, work+isig-1, work+iv-1, work+iw-1, work+ig-1,
phase1, work+ipsi-1, work[ix-1], work[ih-1], work[ihold-1], start,
work[itold-1], work[idelsn-1], iwork[0], nornd, iwork[2], iwork[3],
iwork[4] );
if ( start )
{
work[istart-1] = 1.0;
}
else
{
work[istart-1] = -1.0;
}
if ( phase1 )
{
work[iphase-1] = 1.0;
}
else
{
work[iphase-1] = -1.0;
}
if ( nornd )
{
iwork[1] = 1;
}
else
{
iwork[1] = -1;
}
return;
}
//****************************************************************************80
double r8_epsilon ( )
//****************************************************************************80
//
// Purpose:
//
// R8_EPSILON returns the R8 roundoff unit.
//
// Discussion:
//
// The roundoff unit is a number R which is a power of 2 with the
// property that, to the precision of the computer's arithmetic,
// 1 < 1 + R
// but
// 1 = ( 1 + R / 2 )
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 September 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Output, double R8_EPSILON, the R8 round-off unit.
//
{
const double value = 2.220446049250313E-016;
return value;
}
//****************************************************************************80
double r8_max ( double x, double y )
//****************************************************************************80
//
// Purpose:
//
// R8_MAX returns the maximum of two R8's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 August 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, Y, the quantities to compare.
//
// Output, double R8_MAX, the maximum of X and Y.
//
{
double value;
if ( y < x )
{
value = x;
}
else
{
value = y;
}
return value;
}
//****************************************************************************80
double r8_min ( double x, double y )
//****************************************************************************80
//
// Purpose:
//
// R8_MIN returns the minimum of two R8's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 31 August 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, Y, the quantities to compare.
//
// Output, double R8_MIN, the minimum of X and Y.
//
{
double value;
if ( y < x )
{
value = y;
}
else
{
value = x;
}
return value;
}
//****************************************************************************80
double r8_sign ( double x )
//****************************************************************************80
//
// Purpose:
//
// R8_SIGN returns the sign of an R8.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 October 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, the number whose sign is desired.
//
// Output, double R8_SIGN, the sign of X.
//
{
double value;
if ( x < 0.0 )
{
value = -1.0;
}
else
{
value = 1.0;
}
return value;
}
//****************************************************************************80
void step
(
double &x,
double y[],
const odefun& f,
int neqn,
double &h,
double &eps,
double wt[],
bool &start,
double &hold,
int &k,
int &kold,
bool &crash,
double phi[],
double p[],
double yp[],
double psi[],
double alpha[],
double beta[],
double sig[],
double v[],
double w[],
double g[],
bool &phase1,
int &ns,
bool &nornd
)
//****************************************************************************80
//
// Purpose:
//
// STEP integrates the system of ODEs one step, from X to X+H.
//
// Discussion:
//