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_transistor (@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 differential algebraic equations after solving (DAE--test).
22 %# Run examples with the command
24 %# demo odepkg_testsuite_transistor
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_transistor (vhandle, vrtol)
34 if (nargin ~= 2) %# Check number and types of all input arguments
35 help ('odepkg_testsuite_transistor');
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 vinit = odepkg_testsuite_transistorinit; %# The initial values
55 vmass = odepkg_testsuite_transistormass; %# The mass matrix
57 vopt = odeset ('Refine', 0, 'RelTol', vret{2}, 'AbsTol', vret{3}, ...
58 'InitialStep', vret{4}, 'Stats', 'on', 'NormControl', 'off', ...
59 'Jacobian', @odepkg_testsuite_transistorjac, 'Mass', vmass, ...
60 'MaxStep', vstop-vstart);
62 %# Calculate the algorithm, start timer and do solving
63 tic; vsol = feval (vhandle, @odepkg_testsuite_transistorfun, ...
64 [vstart, vstop], vinit, vopt);
65 vret{12} = toc; %# The value for the elapsed time
66 vref = odepkg_testsuite_transistorref; %# Get the reference solution vector
67 if (exist ('OCTAVE_VERSION') ~= 0)
72 vret{5} = odepkg_testsuite_calcmescd (vlst, vref, vret{3}, vret{2});
73 vret{6} = odepkg_testsuite_calcscd (vlst, vref, vret{3}, vret{2});
74 vret{7} = vsol.stats.nsteps + vsol.stats.nfailed; %# The value for all evals
75 vret{8} = vsol.stats.nsteps; %# The value for success evals
76 vret{9} = vsol.stats.nfevals; %# The value for fun calls
77 vret{10} = vsol.stats.npds; %# The value for partial derivations
78 vret{11} = vsol.stats.ndecomps; %# The value for LU decompositions
80 %# Returns the results for the TRANSISTOR problem
81 function f = odepkg_testsuite_transistorfun (t, y, varargin)
82 ub = 6; uf = 0.026; alpha = 0.99; beta = 1d-6;
83 r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
84 r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
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 f(1,1) = (y(1) - uet) / r0;
92 f(2,1) = y(2) / r1 + (y(2) - ub) / r2 + (1 - alpha) * fac1;
93 f(3,1) = y(3) / r3 - fac1;
94 f(4,1) = (y(4) - ub) / r4 + alpha * fac1;
95 f(5,1) = y(5) / r5 + (y(5) - ub) / r6 + (1 - alpha) * fac2;
96 f(6,1) = y(6) / r7 - fac2;
97 f(7,1) = (y(7) - ub) / r8 + alpha * fac2;
100 %# Returns the INITIAL values for the TRANSISTOR problem
101 function vinit = odepkg_testsuite_transistorinit ()
102 vinit = [0, 3, 3, 6, 3, 3, 6, 0];
104 %# Returns the JACOBIAN matrix for the TRANSISTOR problem
105 function dfdy = odepkg_testsuite_transistorjac (t, y, varargin)
106 ub = 6; uf = 0.026; alpha = 0.99; beta = 1d-6;
107 r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
108 r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
109 r8 = 9000; r9 = 9000;
111 fac1p = beta * exp ((y(2) - y(3)) / uf) / uf;
112 fac2p = beta * exp ((y(5) - y(6)) / uf) / uf;
115 dfdy(2,2) = 1 / r1 + 1 / r2 + (1 - alpha) * fac1p;
116 dfdy(2,3) = - (1 - alpha) * fac1p;
118 dfdy(3,3) = 1 / r3 + fac1p;
119 dfdy(4,2) = alpha * fac1p;
120 dfdy(4,3) = - alpha * fac1p;
122 dfdy(5,5) = 1 / r5 + 1 / r6 + (1 - alpha) * fac2p;
123 dfdy(5,6) = - (1 - alpha) * fac2p;
125 dfdy(6,6) = 1 / r7 + fac2p;
126 dfdy(7,5) = alpha * fac2p;
127 dfdy(7,6) = - alpha * fac2p;
131 %# Returns the MASS matrix for the TRANSISTOR problem
132 function mass = odepkg_testsuite_transistormass (t, y, varargin)
133 mass = [-1e-6, 1e-6, 0, 0, 0, 0, 0, 0; ...
134 1e-6, -1e-6, 0, 0, 0, 0, 0, 0; ...
135 0, 0, -2e-6, 0, 0, 0, 0, 0; ...
136 0, 0, 0, -3e-6, 3e-6, 0, 0, 0; ...
137 0, 0, 0, 3e-6, -3e-6, 0, 0, 0; ...
138 0, 0, 0, 0, 0, -4e-6, 0, 0; ...
139 0, 0, 0, 0, 0, 0, -5e-6, 5e-6; ...
140 0, 0, 0, 0, 0, 0, 5e-6, -5e-6];
142 %# Returns the REFERENCE values for the TRANSISTOR problem
143 function y = odepkg_testsuite_transistorref ()
144 y(1,1) = -0.55621450122627e-2;
145 y(2,1) = 0.30065224719030e+1;
146 y(3,1) = 0.28499587886081e+1;
147 y(4,1) = 0.29264225362062e+1;
148 y(5,1) = 0.27046178650105e+1;
149 y(6,1) = 0.27618377783931e+1;
150 y(7,1) = 0.47709276316167e+1;
151 y(8,1) = 0.12369958680915e+1;
154 %! vsolver = {@odebda, @oders, @ode2r, @ode5r, @odesx};
155 %! for vcnt=1:length (vsolver)
156 %! vtrans{vcnt,1} = odepkg_testsuite_transistor (vsolver{vcnt}, 1e-7);
160 %# Local Variables: ***