7017
|
1 ## Copyright (C) 2006, 2007 John W. Eaton |
7016
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
5590
|
19 %% Automatically generated from DejaGNU files |
|
20 |
|
21 %% test/octave.test/diffeq/lsode-1.m |
|
22 %% dassl-1.m |
|
23 %% |
|
24 %% Test lsode() function |
|
25 %% |
|
26 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
27 %% Comalco Research and Technology |
|
28 %% 20 May 1998 |
|
29 %% |
|
30 %% Problem |
|
31 %% |
|
32 %% y1' = -y2, y1(0) = 1 |
|
33 %% y2' = y1, y2(0) = 0 |
|
34 %% |
|
35 %% Solution |
|
36 %% |
|
37 %% y1(t) = cos(t) |
|
38 %% y2(t) = sin(t) |
|
39 %!function xdot = f (x, t) |
|
40 %! xdot = [-x(2); x(1)]; |
|
41 %!test |
|
42 %! |
|
43 %! x0 = [1; 0]; |
|
44 %! xdot0 = [0; 1]; |
|
45 %! t = (0:1:10)'; |
|
46 %! |
|
47 %! tol = 500 * lsode_options ("relative tolerance"); |
|
48 %! |
|
49 %! |
|
50 %! x = lsode ("f", x0, t); |
|
51 %! |
|
52 %! y = [cos(t), sin(t)]; |
|
53 %! |
|
54 %! assert(all (all (abs (x - y) < tol))); |
|
55 |
|
56 %% test/octave.test/diffeq/lsode-2.m |
|
57 %!function xdotdot = f (x, t) |
|
58 %! xdotdot = [x(2); -x(1)]; |
|
59 %!test |
|
60 %! |
|
61 %! x0 = [1; 0]; |
|
62 %! t = [0; 2*pi]; |
|
63 %! tol = 100 * dassl_options ("relative tolerance"); |
|
64 %! |
|
65 %! x = lsode ("f", x0, t); |
|
66 %! |
|
67 %! y = [1, 0; 1, 0]; |
|
68 %! |
|
69 %! assert(all (all (abs (x - y) < tol))); |
|
70 |
|
71 %% test/octave.test/diffeq/lsode-3.m |
|
72 %!function xdot = f (x, t) |
|
73 %! xdot = x; |
|
74 %!test |
|
75 %! |
|
76 %! x0 = 1; |
|
77 %! t = [0; 1]; |
|
78 %! tol = 100 * dassl_options ("relative tolerance"); |
|
79 %! |
|
80 %! x = lsode ("f", x0, t); |
|
81 %! |
|
82 %! y = [1; e]; |
|
83 %! |
|
84 %! assert(all (all (abs (x - y) < tol))); |
|
85 |
|
86 %% test/octave.test/diffeq/lsode_options-1.m |
|
87 %!test |
|
88 %! lsode_options ("absolute tolerance", eps); |
|
89 %! assert(lsode_options ("absolute tolerance") == eps); |
|
90 |
|
91 %% test/octave.test/diffeq/lsode_options-3.m |
5751
|
92 %!error <Invalid call to lsode_options.*> lsode_options ("foo", 1, 2); |
5590
|
93 |
|
94 %% test/octave.test/diffeq/dassl-1.m |
|
95 %% dassl-1.m |
|
96 %% |
|
97 %% Test dassl() function |
|
98 %% |
|
99 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
100 %% Comalco Research and Technology |
|
101 %% 20 May 1998 |
|
102 %% |
|
103 %% Problem |
|
104 %% |
|
105 %% y1' = -y2, y1(0) = 1 |
|
106 %% y2' = y1, y2(0) = 0 |
|
107 %% |
|
108 %% Solution |
|
109 %% |
|
110 %% y1(t) = cos(t) |
|
111 %% y2(t) = sin(t) |
|
112 %!function res = f (x, xdot, t) |
|
113 %! res = [xdot(1)+x(2); xdot(2)-x(1)]; |
|
114 %!test |
|
115 %! |
|
116 %! x0 = [1; 0]; |
|
117 %! xdot0 = [0; 1]; |
|
118 %! t = (0:1:10)'; |
|
119 %! |
|
120 %! tol = 100 * dassl_options ("relative tolerance"); |
|
121 %! |
|
122 %! |
|
123 %! [x, xdot] = dassl ("f", x0, xdot0, t); |
|
124 %! |
|
125 %! y = [cos(t), sin(t)]; |
|
126 %! |
|
127 %! assert(all (all (abs (x - y) < tol))); |
|
128 |
|
129 %% test/octave.test/diffeq/dassl-2.m |
|
130 %% dassl-2.m |
|
131 %% |
|
132 %% Test dassl() function |
|
133 %% |
|
134 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
135 %% Comalco Research and Technology |
|
136 %% 20 May 1998 |
|
137 %% |
|
138 %% Based on SLATEC quick check for DASSL by Linda Petzold |
|
139 %% |
|
140 %% Problem |
|
141 %% |
|
142 %% x1' + 10*x1 = 0, x1(0) = 1 |
|
143 %% x1 + x2 = 1, x2(0) = 0 |
|
144 %% |
|
145 %% |
|
146 %% Solution |
|
147 %% |
|
148 %% x1(t) = exp(-10*t) |
|
149 %% x2(t) = 1 - x(1) |
|
150 %!function res = f (x, xdot, t) |
|
151 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1]; |
|
152 %!test |
|
153 %! |
|
154 %! x0 = [1; 0]; |
|
155 %! xdot0 = [-10; 10]; |
|
156 %! t = (0:0.2:1)'; |
|
157 %! |
|
158 %! tol = 500 * dassl_options ("relative tolerance"); |
|
159 %! |
|
160 %! |
|
161 %! [x, xdot] = dassl ("f", x0, xdot0, t); |
|
162 %! |
|
163 %! y = [exp(-10*t), 1-exp(-10*t)]; |
|
164 %! |
|
165 %! assert(all (all (abs (x - y) < tol))); |
|
166 |
|
167 %% test/octave.test/diffeq/dassl_options-1.m |
|
168 %!test |
|
169 %! dassl_options ("absolute tolerance", eps); |
|
170 %! assert(dassl_options ("absolute tolerance") == eps); |
|
171 |
|
172 %% test/octave.test/diffeq/dassl_options-3.m |
5751
|
173 %!error <Invalid call to dassl_options.*> dassl_options ("foo", 1, 2); |
5590
|
174 |