1 %# Copyright (C) 2007-2012, Thomas Treichl <treichl@users.sourceforge.net>
2 %# OdePkg - A package for solving ordinary differential equations and more
4 %# This program is free software; you can redistribute it and/or modify
5 %# it under the terms of the GNU General Public License as published by
6 %# the Free Software Foundation; either version 2 of the License, or
7 %# (at your option) any later version.
9 %# This program is distributed in the hope that it will be useful,
10 %# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 %# GNU General Public License for more details.
14 %# You should have received a copy of the GNU General Public License
15 %# along with this program; If not, see <http://www.gnu.org/licenses/>.
18 %# @deftypefn {Function File} {[@var{solution}] =} odepkg_testsuite_impltrans (@var{@@solver}, @var{reltol})
20 %# If this function is called with two input arguments and the first input argument @var{@@solver} is a function handle describing an OdePkg solver and the second input argument @var{reltol} is a double scalar describing the relative error tolerance then return the cell array @var{solution} with performance informations about the TRANSISTOR testsuite of implicit differential algebraic equations after solving (IDE--test).
22 %# Run examples with the command
24 %# demo odepkg_testsuite_impltrans
27 %# This function has been ported from the "Test Set for IVP solvers" which is developed by the INdAM Bari unit project group "Codes and Test Problems for Differential Equations", coordinator F. Mazzia.
32 function vret = odepkg_testsuite_impltrans (vhandle, vrtol)
34 if (nargin ~= 2) %# Check number and types of all input arguments
35 help ('odepkg_testsuite_impltrans');
36 error ('OdePkg:InvalidArgument', ...
37 'Number of input arguments must be exactly two');
38 elseif (~isa (vhandle, 'function_handle') || ~isscalar (vrtol))
42 vret{1} = vhandle; %# The handle for the solver that is used
43 vret{2} = vrtol; %# The value for the realtive tolerance
44 vret{3} = vret{2}; %# The value for the absolute tolerance
45 vret{4} = vret{2}; %# The value for the first time step
46 %# Write a debug message on the screen, because this testsuite function
47 %# may be called more than once from a loop over all solvers present
48 fprintf (1, ['Testsuite TRANSISTOR, testing solver %7s with relative', ...
49 ' tolerance %2.0e\n'], func2str (vret{1}), vrtol); fflush (1);
51 %# Setting the integration algorithms option values
52 vstart = 0.0; %# The point of time when solving is started
53 vstop = 0.2; %# The point of time when solving is stoped
54 [vinity, vinityd] = odepkg_testsuite_impltransinit; %# The initial values
56 vopt = odeset ('Refine', 0, 'RelTol', vret{2}, 'AbsTol', vret{3}, ...
57 'InitialStep', vret{4}, 'Stats', 'on', 'NormControl', 'off', ...
58 'Jacobian', @odepkg_testsuite_impltransjac, 'MaxStep', vstop-vstart);
59 %# ,'OutputFcn', @odeplot, 'MaxStep', 1e-4);
61 %# Calculate the algorithm, start timer and do solving
62 tic; vsol = feval (vhandle, @odepkg_testsuite_impltransfun, ...
63 [vstart, vstop], vinity, vinityd', vopt);
64 vret{12} = toc; %# The value for the elapsed time
65 vref = odepkg_testsuite_impltransref; %# Get the reference solution vector
66 if (exist ('OCTAVE_VERSION') ~= 0)
71 vret{5} = odepkg_testsuite_calcmescd (vlst, vref, vret{3}, vret{2});
72 vret{6} = odepkg_testsuite_calcscd (vlst, vref, vret{3}, vret{2});
73 vret{7} = vsol.stats.nsteps + vsol.stats.nfailed; %# The value for all evals
74 vret{8} = vsol.stats.nsteps; %# The value for success evals
75 vret{9} = vsol.stats.nfevals; %# The value for fun calls
76 vret{10} = vsol.stats.npds; %# The value for partial derivations
77 vret{11} = vsol.stats.ndecomps; %# The value for LU decompositions
79 %# Returns the results for the implicit TRANSISTOR problem
80 function res = odepkg_testsuite_impltransfun (t, y, yd, varargin)
81 ub = 6; uf = 0.026; alpha = 0.99; beta = 1e-6;
82 r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
83 r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
84 r8 = 9000; r9 = 9000; c1 = 1e-6; c2 = 2e-6;
85 c3 = 3e-6; c4 = 4e-6; c5 = 5e-6;
87 uet = 0.1 * sin(200 * pi * t);
88 fac1 = beta * (exp((y(2) - y(3)) / uf) - 1);
89 fac2 = beta * (exp((y(5) - y(6)) / uf) - 1);
91 res(1,1) = (y(1) - uet) / r0 + c1 * yd(1) - c1 * yd(2);
92 res(2,1) = y(2) / r1 + (y(2) - ub) / r2 + (1 - alpha) * fac1 - c1 * yd(1) + c1 * yd(2);
93 res(3,1) = y(3) / r3 - fac1 + c2 * yd(3);
94 res(4,1) = (y(4) - ub) / r4 + alpha * fac1 + c3 * yd(4) - c3 * yd(5);
95 res(5,1) = y(5) / r5 + (y(5) - ub) / r6 + (1 - alpha) * fac2 - c3 * yd(4) + c3 * yd(5);
96 res(6,1) = y(6) / r7 - fac2 + c4 * yd(6);
97 res(7,1) = (y(7) - ub) / r8 + alpha * fac2 + c5 * yd(7) - c5 * yd(8);
98 res(8,1) = y(8) / r9 - c5 * yd(7) + c5 * yd(8);
100 %# Returns the INITIAL values for the TRANSISTOR problem
101 function [y0, yd0] = odepkg_testsuite_impltransinit ()
102 y0 = [0, 3, 3, 6, 3, 3, 6, 0];
103 yd0 = 1e-3 * [0, 0, 1/3, 0, 0, 1/3, 0, 0];
104 %# yd0 = [ 51.338775, 51.338775, -166.666666, -24.975766, ...
105 %# -24.975766, -83.333333, -10.0056445, -10.005644];
107 %# Returns the JACOBIAN matrix for the TRANSISTOR problem
108 function [dfdy, dfdyd] = odepkg_testsuite_impltransjac (t, y, varargin)
109 ub = 6; uf = 0.026; alpha = 0.99; beta = 1e-6;
110 r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
111 r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
112 r8 = 9000; r9 = 9000; c1 = 1e-6; c2 = 2e-6;
113 c3 = 3e-6; c4 = 4e-6; c5 = 5e-6;
115 fac1p = beta * exp ((y(2) - y(3)) / uf) / uf;
116 fac2p = beta * exp ((y(5) - y(6)) / uf) / uf;
119 dfdy(2,2) = 1 / r1 + 1 / r2 + (1 - alpha) * fac1p;
120 dfdy(2,3) = - (1 - alpha) * fac1p;
122 dfdy(3,3) = 1 / r3 + fac1p;
123 dfdy(4,2) = alpha * fac1p;
124 dfdy(4,3) = - alpha * fac1p;
126 dfdy(5,5) = 1 / r5 + 1 / r6 + (1 - alpha) * fac2p;
127 dfdy(5,6) = - (1 - alpha) * fac2p;
129 dfdy(6,6) = 1 / r7 + fac2p;
130 dfdy(7,5) = alpha * fac2p;
131 dfdy(7,6) = - alpha * fac2p;
135 dfdyd = [ c1, -c1, 0, 0, 0, 0, 0, 0; ...
136 -c1, c1, 0, 0, 0, 0, 0, 0; ...
137 0, 0, c2, 0, 0, 0, 0, 0; ...
138 0, 0, 0, c3, -c3, 0, 0, 0; ...
139 0, 0, 0, -c3, c3, 0, 0, 0; ...
140 0, 0, 0, 0, 0, c4, 0, 0; ...
141 0, 0, 0, 0, 0, 0, c5, -c5; ...
142 0, 0, 0, 0, 0, 0, -c5, c5];
144 %# For the implicit form of the TRANSISTOR problem a mass matrix is
145 %# not needed. This mass matrix is needed if the problem is formulated
146 %# in explicit form (cf. odepkg_testsuite_transistor.m).
147 %# function mass = odepkg_testsuite_impltransmass (t, y, varargin)
148 %# mass = [-1e-6, 1e-6, 0, 0, 0, 0, 0, 0; ...
149 %# 1e-6, -1e-6, 0, 0, 0, 0, 0, 0; ...
150 %# 0, 0, -2e-6, 0, 0, 0, 0, 0; ...
151 %# 0, 0, 0, -3e-6, 3e-6, 0, 0, 0; ...
152 %# 0, 0, 0, 3e-6, -3e-6, 0, 0, 0; ...
153 %# 0, 0, 0, 0, 0, -4e-6, 0, 0; ...
154 %# 0, 0, 0, 0, 0, 0, -5e-6, 5e-6; ...
155 %# 0, 0, 0, 0, 0, 0, 5e-6, -5e-6];
157 %# Returns the REFERENCE values for the TRANSISTOR problem
158 function y = odepkg_testsuite_impltransref ()
159 y(1,1) = -0.55621450122627e-2;
160 y(2,1) = 0.30065224719030e+1;
161 y(3,1) = 0.28499587886081e+1;
162 y(4,1) = 0.29264225362062e+1;
163 y(5,1) = 0.27046178650105e+1;
164 y(6,1) = 0.27618377783931e+1;
165 y(7,1) = 0.47709276316167e+1;
166 y(8,1) = 0.12369958680915e+1;
169 %! vsolver = {@odebdi};
170 %! for vcnt=1:length (vsolver)
171 %! vtrans{vcnt,1} = odepkg_testsuite_impltrans (vsolver{vcnt}, 1e-7);
175 %# Local Variables: ***