-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolve_ARK.m
639 lines (526 loc) · 20 KB
/
solve_ARK.m
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
function [tvals, Y, nsteps, lits] = solve_ARK(fe,fi,Ji,tvals,Y0,Be,Bi,rtol,atol,hmin,hmax,hinit)
% usage: [tvals, Y, nsteps, lits] = solve_ARK(fe,fi,Ji,tvals,Y0,Be,Bi,rtol,atol,hmin,hmax,hinit)
%
% Adaptive time step additive Runge-Kutta solver for the
% vector-valued ODE problem
% y' = fe(t,Y) + fi(t,Y), t in tvals, y in R^m,
% Y(t0) = [y1(t0), y2(t0), ..., ym(t0)]'.
%
% Inputs:
% fe = function handle for fe(t,Y)
% fi = function handle for fi(t,Y)
% Ji = function handle for Jacobian of fi, J(t,Y)
% tvals = [t0, t1, t2, ..., tN]
% Y0 = initial value array (column vector of length m)
% Be,Bi = Butcher table matrices for ARK coefficients, of the form
% Be = [ce Ae; Bi = [ci Ai;
% q be; q bi;
% p be2 ] p bi2 ]
% Here, ce,ci are vectors of stage time fractions (s-by-1),
% Ae,Ai are matrices of Butcher coefficients (s-by-s),
% q is an integer denoting the method order of accuracy,
% be,bi are vectors of solution weights (1-by-s),
% p is an integer denoting the embedding order of accuracy,
% be2,bi2 are vectors of embedding weights (1-by-s),
% The [p, be2] and [p, bi2] rows are optional. If
% both of those are not provided the method will default to
% taking fixed step sizes of size hmin.
% rtol = desired relative error of solution (scalar)
% atol = desired absolute error of solution (vector or scalar)
% hmin = minimum internal time step size (hmin <= t(i)-t(i-1), for all i)
% hmax = maximum internal time step size (hmax >= hmin)
% hinit = initial internal time step size (hmin <= hinit <= hmax)
%
% Outputs:
% tvals = the same as the input array tvals
% y = [y(t0), y(t1), y(t2), ..., y(tN)], where each
% y(t*) is a column vector of length m.
% nsteps = number of internal time steps taken by method
% lits = number of linear solves required by method
%
% Note: to run in fixed-step mode, call with hmin=hmax as the desired
% time step size, and set the tolerances to large positive numbers.
%
% Daniel R. Reynolds
% Department of Mathematics
% Southern Methodist University
% March 2017
% All Rights Reserved
% check for compatible Be,Bi tables
if (size(Be) ~= size(Bi))
error('solve_ARK error: Be and Bi must have the same size')
end
s = size(Be,2) - 1; % number of stages
if (Be(s+1,1) ~= Bi(s+1,1))
error('solve_ARK error: Be and Bi must have the same method order')
end
if (size(Be,1) > size(Be,2))
if (Be(s+1,2) ~= Bi(s+1,2))
error('solve_ARK error: Be and Bi must have the same embedding order')
end
end
% determine whether adaptivity is desired
adaptive = 0;
if (abs(hmax-hmin)/abs(hmax) > sqrt(eps))
adaptive = 1;
end
% if adaptivity enabled, determine approach for error estimation,
% and set the lower-order of accuracy accordingly
[Brows, Bcols] = size(Be);
embedded = 0;
p = 0;
if (hmax > hmin) % check whether adaptivity is desired
if (Brows > Bcols)
if ( (max(abs(Be(Bcols+1,2:Bcols))) > eps) && ...
(max(abs(Bi(Bcols+1,2:Bcols))) > eps) ) % check for embedding coeffs
embedded = 1;
p = Be(Bcols+1,1);
end
end
end
if (embedded == 0)
p = Be(Bcols,1);
end
% initialize output arrays
N = length(tvals);
m = length(Y0);
Y = zeros(m,N);
Y(:,1) = Y0;
% initialize diagnostics
c_fails = 0; % total convergence failures
a_fails = 0; % total accuracy failures
% set the solver parameters
h_reduce = 0.1; % failed step reduction factor
h_safety = 0.9; % adaptivity safety factor
h_growth = 10; % adaptivity growth bound
ONEMSM = 1-sqrt(eps); % coefficients to account for
ONEPSM = 1+sqrt(eps); % floating-point roundoff
ERRTOL = 1.1; % upper bound on allowed step error
% (in WRMS norm)
% initialize temporary variables
t = tvals(1);
Ynew = Y0;
% set initial time step size
h = hinit;
% initialize work counters
nsteps = 0;
lits = 0;
% iterate over output time steps
for tstep = 2:length(tvals)
% loop over internal time steps to get to desired output time
while ((t-tvals(tstep))*h < 0)
% bound internal time step
h = max([h, hmin]); % enforce minimum time step size
h = min([h, hmax]); % maximum time step size
h = min([h, tvals(tstep)-t]); % stop at output time
% reset stage failure flag
st_fail = 0;
% call stepper routine to take the step and compute error
% estimate (if applicable); increment internal time steps counter
if (adaptive)
if (embedded)
[Ynew,Yerr,cfail,lin] = ARKstep_embedded(fe, fi, Ji, Y0, t, h, Be, Bi);
nsteps = nsteps + 1;
else
[Ynew,Yerr,cfail,lin] = ARKstep_Richardson(fe, fi, Ji, Y0, t, h, Be, Bi);
nsteps = nsteps + 3;
end
else
[Ynew,cfail,lin] = ARKstep_basic(fe, fi, Ji, Y0, t, h, Be, Bi);
nsteps = nsteps + 1;
end
% increment linear iteration counter
lits = lits + lin;
% check for nonlinear convergence/divergence
if (cfail ~= 0)
st_fail = 1;
c_fails = c_fails + 1;
end
% if stages succeeded and time step adaptivity enabled, check step accuracy
if ((st_fail == 0) & adaptive)
% estimate error in current step
err_step = max(norm(Yerr./(rtol*Ynew + atol),inf), eps);
% if error too high, flag step as a failure (will be be recomputed)
if (err_step > ERRTOL*ONEPSM)
a_fails = a_fails + 1;
st_fail = 1;
end
end
% if step was successful (solves succeeded, and error acceptable)
if (st_fail == 0)
% update solution and time for last successful step
Y0 = Ynew;
t = t + h;
% for adaptive methods, use error estimate to adapt the time step
if (adaptive)
h_old = h;
if (err_step == 0.0) % no error, set max possible
h = tvals(end)-t;
else % set next h (I-controller)
h = h_safety * h_old * err_step^(-1.0/p);
end
% enforce maximum growth rate on step sizes
h = min(h_growth*h_old, h);
% otherwise, just use the fixed minimum input step size
else
h = hmin;
end
% if step solves or error test failed
else
% if already at minimum step, just return with failure
if (h <= hmin)
error('Cannot achieve desired accuracy.\n Consider reducing hmin or increasing rtol.\n');
end
% otherwise, reset guess, reduce time step, retry solve
Ynew = Y0;
h = h * h_reduce;
end % end logic tests for step success/failure
end % end while loop attempting to solve steps to next output time
% store updated solution in output array
Y(:,tstep) = Ynew;
end % time step loop
% end solve_ARK function
end
%------------------------- Utility routines -------------------------%
function [y,yerr,cfail,lits] = ARKstep_embedded(fe, fi, Ji, y0, t0, h, Be, Bi)
% Inputs:
% fe = function handle for fe(t,Y)
% fi = function handle for fi(t,Y)
% Ji = function handle for Jacobian of fi, J(t,Y)
% y0 = solution at beginning of time step
% t0 = 'time' at beginning of time step
% h = step size to take
% Be = explicit Butcher table to use
% Bi = implicit Butcher table to use
%
% Outputs:
% y = new solution at t0+h
% yerr = error vector
% cfail = convergence failure flag (0=success; 1=failure)
% lits = total linear iterations for step
% extract ERK method information from Be
[Brows, Bcols] = size(Be);
s = Bcols - 1; % number of stages
ce = Be(1:s,1); % stage time fraction array
be = (Be(s+1,2:s+1))'; % solution weights (convert to column)
Ae = Be(1:s,2:s+1); % RK coefficients
de = (Be(s+2,2:s+1))'; % embedding coefficients
% extract DIRK method information from Bi
[Brows, Bcols] = size(Bi);
ci = Bi(1:s,1); % stage time fraction array
bi = (Bi(s+1,2:s+1))'; % solution weights (convert to column)
Ai = Bi(1:s,2:s+1); % RK coefficients
di = (Be(s+2,2:s+1))'; % embedding coefficients
% initialize storage for RHS vectors, outputs
ke = zeros(length(y0),s);
ki = zeros(length(y0),s);
lits = 0;
cfail = 0;
% set the solver parameters
newt_maxit = 20; % max number of Newton iterations
newt_ftol = 1e-10; % Newton solver residual tolerance
newt_stol = 1e-10; % Newton solver solution tolerance
% set function names for Newton solver residual/Jacobian
Fun = @F_ARK;
Jac = @A_ARK;
% set Fdata values for this step
Fdata.fe = fe; % ODE RHS function names
Fdata.fi = fi;
Fdata.Ji = Ji; % ODE RHS Jacobian function name
Fdata.Be = Be; % Butcher tables
Fdata.Bi = Bi;
Fdata.s = s; % number of stages
Fdata.h = h; % current step size
Fdata.yold = y0; % solution from previous step
Fdata.t = t0; % time of last successful step
% loop over stages
for stage = 1:s
% set Newton initial guess as previous stage solution
z = y0;
% set current stage index into Fdata structure
Fdata.stage = stage;
% construct RHS comprised of old time data
% zi = y_n + h*ai(i,i)*fi(i) + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% <=>
% zi - h*(ai(i,i)*fi) = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% =>
% rhs = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
Fdata.rhs = y0;
for j = 1:stage-1
Fdata.rhs = Fdata.rhs + h*Ae(stage,j)*ke(:,j) + h*Ai(stage,j)*ki(:,j);
end
% call Newton solver to compute new stage solution
[z,lin,ierr] = newton(Fun, Jac, z, Fdata, newt_ftol, newt_stol, newt_maxit);
% increment total linear solver statistics
lits = lits + lin;
% if Newton method failed, set relevant flags/statistics
% and break out of stage loop
if (ierr ~= 0)
cfail = 1;
return;
end
% construct new stage RHS
ke(:,stage) = fe(t0+h*ce(stage),z);
ki(:,stage) = fi(t0+h*ci(stage),z);
end
% compute new solution and error estimate
% ynew = yold + h*sum(be(j)*fe(j)) + h*sum(bi(j)*fi(j))
y = y0 + h*ke*be + h*ki*bi;
yerr = h*ke*(be-de) + h*ki*(bi-di);
% end of function
end
function [y,cfail,lits] = ARKstep_basic(fe, fi, Ji, y0, t0, h, Be, Bi)
% Inputs:
% fe = function handle for fe(t,Y)
% fi = function handle for fi(t,Y)
% Ji = function handle for Jacobian of fi, J(t,Y)
% y0 = solution at beginning of time step
% t0 = 'time' at beginning of time step
% h = step size to take
% Be = explicit Butcher table to use
% Bi = implicit Butcher table to use
%
% Outputs:
% y = new solution at t0+h
% cfail = convergence failure flag (0=success; 1=failure)
% lits = total linear iterations for step
% extract ERK method information from Be
[Brows, Bcols] = size(Be);
s = Bcols - 1; % number of stages
ce = Be(1:s,1); % stage time fraction array
be = (Be(s+1,2:s+1))'; % solution weights (convert to column)
Ae = Be(1:s,2:s+1); % RK coefficients
de = (Be(s+2,2:s+1))'; % embedding coefficients
% extract DIRK method information from Bi
[Brows, Bcols] = size(Bi);
ci = Bi(1:s,1); % stage time fraction array
bi = (Bi(s+1,2:s+1))'; % solution weights (convert to column)
Ai = Bi(1:s,2:s+1); % RK coefficients
di = (Be(s+2,2:s+1))'; % embedding coefficients
% initialize storage for RHS vectors, outputs
ke = zeros(length(y0),s);
ki = zeros(length(y0),s);
lits = 0;
cfail = 0;
% set the solver parameters
newt_maxit = 20; % max number of Newton iterations
newt_ftol = 1e-10; % Newton solver residual tolerance
newt_stol = 1e-10; % Newton solver solution tolerance
% set function names for Newton solver residual/Jacobian
Fun = @F_ARK;
Jac = @A_ARK;
% set Fdata values for this step
Fdata.fe = fe; % ODE RHS function names
Fdata.fi = fi;
Fdata.Ji = Ji; % ODE RHS Jacobian function name
Fdata.Be = Be; % Butcher tables
Fdata.Bi = Bi;
Fdata.s = s; % number of stages
Fdata.h = h; % current step size
Fdata.yold = y0; % solution from previous step
Fdata.t = t0; % time of last successful step
% loop over stages
for stage = 1:s
% set Newton initial guess as previous stage solution
z = y0;
% set current stage index into Fdata structure
Fdata.stage = stage;
% construct RHS comprised of old time data
% zi = y_n + h*ai(i,i)*fi(i) + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% <=>
% zi - h*(ai(i,i)*fi) = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% =>
% rhs = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
Fdata.rhs = y0;
for j = 1:stage-1
Fdata.rhs = Fdata.rhs + h*Ae(stage,j)*ke(:,j) + h*Ai(stage,j)*ki(:,j);
end
% call Newton solver to compute new stage solution
[z,lin,ierr] = newton(Fun, Jac, z, Fdata, newt_ftol, newt_stol, newt_maxit);
% increment total linear solver statistics
lits = lits + lin;
% if Newton method failed, set relevant flags/statistics
% and break out of stage loop
if (ierr ~= 0)
cfail = 1;
return;
end
% construct new stage RHS
ke(:,stage) = fe(t0+h*ce(stage),z);
ki(:,stage) = fi(t0+h*ci(stage),z);
end
% compute new solution, ynew = yold + h*sum(be(j)*fe(j)) + h*sum(bi(j)*fi(j))
y = y0 + h*ke*be + h*ki*bi;
% end of function
end
function [y,yerr,cfail,lits] = ARKstep_Richardson(fe, fi, Ji, y0, t0, h, Be, Bi)
% Inputs:
% fe = function handle for fe(t,Y)
% fi = function handle for fi(t,Y)
% Ji = function handle for Jacobian of fi, J(t,Y)
% y0 = solution at beginning of time step
% t0 = 'time' at beginning of time step
% h = step size to take
% Be = explicit Butcher table to use
% Bi = implicit Butcher table to use
%
% Outputs:
% y = new solution at t0+h
% yerr = error vector
% cfail = convergence failure flag (0=success; 1=failure)
% lits = total linear iterations for step
% extract ERK method information from Be
[Brows, Bcols] = size(Be);
s = Bcols - 1; % number of stages
ce = Be(1:s,1); % stage time fraction array
be = (Be(s+1,2:s+1))'; % solution weights (convert to column)
Ae = Be(1:s,2:s+1); % RK coefficients
de = (Be(s+2,2:s+1))'; % embedding coefficients
p = Be(Bcols,1);
% extract DIRK method information from Bi
[Brows, Bcols] = size(Bi);
ci = Bi(1:s,1); % stage time fraction array
bi = (Bi(s+1,2:s+1))'; % solution weights (convert to column)
Ai = Bi(1:s,2:s+1); % RK coefficients
di = (Be(s+2,2:s+1))'; % embedding coefficients
% initialize storage for RHS vectors, outputs
ke = zeros(length(y0),s);
ki = zeros(length(y0),s);
lits = 0;
cfail = 0;
% set the solver parameters
newt_maxit = 20; % max number of Newton iterations
newt_ftol = 1e-10; % Newton solver residual tolerance
newt_stol = 1e-10; % Newton solver solution tolerance
% set function names for Newton solver residual/Jacobian
Fun = @F_ARK;
Jac = @A_ARK;
% set Fdata values for this step
Fdata.fe = fe; % ODE RHS function names
Fdata.fi = fi;
Fdata.Ji = Ji; % ODE RHS Jacobian function name
Fdata.Be = Be; % Butcher tables
Fdata.Bi = Bi;
Fdata.s = s; % number of stages
Fdata.h = h; % current step size
Fdata.yold = y0; % solution from previous step
Fdata.t = t0; % time of last successful step
% First compute solution with a single step
for stage = 1:s
% set Newton initial guess as previous stage solution
z = y0;
% set current stage index into Fdata structure
Fdata.stage = stage;
% construct RHS comprised of old time data
% zi = y_n + h*ai(i,i)*fi(i) + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% <=>
% zi - h*(ai(i,i)*fi) = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
% =>
% rhs = y_n + h*sum_{j=1}^{i-1} [ae(i,j)*fe(j) + ai(i,j)*fi(j)]
Fdata.rhs = y0;
for j = 1:stage-1
Fdata.rhs = Fdata.rhs + h*Ae(stage,j)*ke(:,j) + h*Ai(stage,j)*ki(:,j);
end
% call Newton solver to compute new stage solution
[z,lin,ierr] = newton(Fun, Jac, z, Fdata, newt_ftol, newt_stol, newt_maxit);
% increment total linear solver statistics
lits = lits + lin;
% if Newton method failed, set relevant flags/statistics
% and break out of stage loop
if (ierr ~= 0)
cfail = 1;
return;
end
% construct new stage RHS
ke(:,stage) = fe(t0+h*ce(stage),z);
ki(:,stage) = fi(t0+h*ci(stage),z);
end
% compute full step solution, ynew = yold + h*sum(be(j)*fe(j)) + h*sum(bi(j)*fi(j))
y1 = y0 + h*ke*be + h*ki*bi;
% Second compute solution with two half steps
Fdata.h = h/2;
for stage = 1:s
z = y0; % consider 'smarter' approach for constructing
% initial guess using results from full-step solution
Fdata.stage = stage;
Fdata.rhs = y0;
for j = 1:stage-1
Fdata.rhs = Fdata.rhs + h/2*Ae(stage,j)*ke(:,j) + h/2*Ai(stage,j)*ki(:,j);
end
[z,lin,ierr] = newton(Fun, Jac, z, Fdata, newt_ftol, newt_stol, newt_maxit);
lits = lits + lin;
if (ierr ~= 0)
cfail = 1;
return;
end
ke(:,stage) = fe(t0+h*ce(stage),z);
ki(:,stage) = fi(t0+h*ci(stage),z);
end
y2 = y0 + h/2*ke*be + h/2*ki*bi;
Fdata.yold = y2;
Fdata.t = t0+h/2;
for stage = 1:s
z = y2;
Fdata.stage = stage;
Fdata.rhs = y0;
for j = 1:stage-1
Fdata.rhs = Fdata.rhs + h/2*Ae(stage,j)*ke(:,j) + h/2*Ai(stage,j)*ki(:,j);
end
[z,lin,ierr] = newton(Fun, Jac, z, Fdata, newt_ftol, newt_stol, newt_maxit);
lits = lits + lin;
if (ierr ~= 0)
cfail = 1;
return;
end
ke(:,stage) = fe(t0+h*ce(stage),z);
ki(:,stage) = fi(t0+h*ci(stage),z);
end
y2 = y2 + h/2*ke*be + h/2*ki*bi;
% Compute Richardson extrapolant and error estimate
y = (2^p)/(2^p-1)*y2 - 1/(2^p-1)*y1;
yerr = 1/(2^p-1)*(y1-y2);
% end of function
end
function F = F_ARK(z, Fdata)
% Inputs: z = current guess for stage solution
% Fdata = structure containing extra information for evaluating F.
% Outputs: F = residual at current guess
%
% This function computes the (non)linear residuals for an intermediate
% stage solution, through calling the user-supplied (in Fdata) ODE
% right-hand side function.
% extract ARK method information from Fdata
Bi = Fdata.Bi;
[Brows, Bcols] = size(Bi);
s = Bcols - 1;
ci = Bi(1:s,1);
Ai = Bi(1:s,2:s+1);
h = Fdata.h;
st = Fdata.stage;
t = Fdata.t + Fdata.h*ci(st);
% form the ARK residual
% F = z - rhs - h*(ai(stage,stage)*fstage)
F = z - Fdata.rhs - h*Ai(st,st)*Fdata.fi(t, z);
% end of function
end
function Amat = A_ARK(z, Fdata)
% Inputs: z = current guess for stage solution
% Fdata = structure containing extra information for evaluating F.
% Outputs: Amat = Jacobian at current guess
%
% This function computes the Jacobian of each intermediate stage residual
% for a multi-stage ARK method, through calling the user-supplied (in
% Fdata) ODE Jacobian function.
% extract ARK method information from Fdata
Bi = Fdata.Bi;
[Brows, Bcols] = size(Bi);
s = Bcols - 1;
ci = Bi(1:s,1);
bi = (Bi(s+1,2:s+1))';
Ai = Bi(1:s,2:s+1);
st = Fdata.stage;
t = Fdata.t + Fdata.h*ci(st);
% form the ARK Jacobian
Amat = eye(length(z)) - Fdata.h*Ai(st,st)*Fdata.Ji(t, z);
% end of function
end