5590
|
1 %% Automatically generated from DejaGNU files |
|
2 |
|
3 %% test/octave.test/diffeq/lsode-1.m |
|
4 %% dassl-1.m |
|
5 %% |
|
6 %% Test lsode() function |
|
7 %% |
|
8 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
9 %% Comalco Research and Technology |
|
10 %% 20 May 1998 |
|
11 %% |
|
12 %% Problem |
|
13 %% |
|
14 %% y1' = -y2, y1(0) = 1 |
|
15 %% y2' = y1, y2(0) = 0 |
|
16 %% |
|
17 %% Solution |
|
18 %% |
|
19 %% y1(t) = cos(t) |
|
20 %% y2(t) = sin(t) |
|
21 %!function xdot = f (x, t) |
|
22 %! xdot = [-x(2); x(1)]; |
|
23 %!test |
|
24 %! |
|
25 %! x0 = [1; 0]; |
|
26 %! xdot0 = [0; 1]; |
|
27 %! t = (0:1:10)'; |
|
28 %! |
|
29 %! tol = 500 * lsode_options ("relative tolerance"); |
|
30 %! |
|
31 %! |
|
32 %! x = lsode ("f", x0, t); |
|
33 %! |
|
34 %! y = [cos(t), sin(t)]; |
|
35 %! |
|
36 %! assert(all (all (abs (x - y) < tol))); |
|
37 |
|
38 %% test/octave.test/diffeq/lsode-2.m |
|
39 %!function xdotdot = f (x, t) |
|
40 %! xdotdot = [x(2); -x(1)]; |
|
41 %!test |
|
42 %! |
|
43 %! x0 = [1; 0]; |
|
44 %! t = [0; 2*pi]; |
|
45 %! tol = 100 * dassl_options ("relative tolerance"); |
|
46 %! |
|
47 %! x = lsode ("f", x0, t); |
|
48 %! |
|
49 %! y = [1, 0; 1, 0]; |
|
50 %! |
|
51 %! assert(all (all (abs (x - y) < tol))); |
|
52 |
|
53 %% test/octave.test/diffeq/lsode-3.m |
|
54 %!function xdot = f (x, t) |
|
55 %! xdot = x; |
|
56 %!test |
|
57 %! |
|
58 %! x0 = 1; |
|
59 %! t = [0; 1]; |
|
60 %! tol = 100 * dassl_options ("relative tolerance"); |
|
61 %! |
|
62 %! x = lsode ("f", x0, t); |
|
63 %! |
|
64 %! y = [1; e]; |
|
65 %! |
|
66 %! assert(all (all (abs (x - y) < tol))); |
|
67 |
|
68 %% test/octave.test/diffeq/lsode_options-1.m |
|
69 %!test |
|
70 %! lsode_options ("absolute tolerance", eps); |
|
71 %! assert(lsode_options ("absolute tolerance") == eps); |
|
72 |
|
73 %% test/octave.test/diffeq/lsode_options-3.m |
5751
|
74 %!error <Invalid call to lsode_options.*> lsode_options ("foo", 1, 2); |
5590
|
75 |
|
76 %% test/octave.test/diffeq/dassl-1.m |
|
77 %% dassl-1.m |
|
78 %% |
|
79 %% Test dassl() function |
|
80 %% |
|
81 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
82 %% Comalco Research and Technology |
|
83 %% 20 May 1998 |
|
84 %% |
|
85 %% Problem |
|
86 %% |
|
87 %% y1' = -y2, y1(0) = 1 |
|
88 %% y2' = y1, y2(0) = 0 |
|
89 %% |
|
90 %% Solution |
|
91 %% |
|
92 %% y1(t) = cos(t) |
|
93 %% y2(t) = sin(t) |
|
94 %!function res = f (x, xdot, t) |
|
95 %! res = [xdot(1)+x(2); xdot(2)-x(1)]; |
|
96 %!test |
|
97 %! |
|
98 %! x0 = [1; 0]; |
|
99 %! xdot0 = [0; 1]; |
|
100 %! t = (0:1:10)'; |
|
101 %! |
|
102 %! tol = 100 * dassl_options ("relative tolerance"); |
|
103 %! |
|
104 %! |
|
105 %! [x, xdot] = dassl ("f", x0, xdot0, t); |
|
106 %! |
|
107 %! y = [cos(t), sin(t)]; |
|
108 %! |
|
109 %! assert(all (all (abs (x - y) < tol))); |
|
110 |
|
111 %% test/octave.test/diffeq/dassl-2.m |
|
112 %% dassl-2.m |
|
113 %% |
|
114 %% Test dassl() function |
|
115 %% |
|
116 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
117 %% Comalco Research and Technology |
|
118 %% 20 May 1998 |
|
119 %% |
|
120 %% Based on SLATEC quick check for DASSL by Linda Petzold |
|
121 %% |
|
122 %% Problem |
|
123 %% |
|
124 %% x1' + 10*x1 = 0, x1(0) = 1 |
|
125 %% x1 + x2 = 1, x2(0) = 0 |
|
126 %% |
|
127 %% |
|
128 %% Solution |
|
129 %% |
|
130 %% x1(t) = exp(-10*t) |
|
131 %% x2(t) = 1 - x(1) |
|
132 %!function res = f (x, xdot, t) |
|
133 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1]; |
|
134 %!test |
|
135 %! |
|
136 %! x0 = [1; 0]; |
|
137 %! xdot0 = [-10; 10]; |
|
138 %! t = (0:0.2:1)'; |
|
139 %! |
|
140 %! tol = 500 * dassl_options ("relative tolerance"); |
|
141 %! |
|
142 %! |
|
143 %! [x, xdot] = dassl ("f", x0, xdot0, t); |
|
144 %! |
|
145 %! y = [exp(-10*t), 1-exp(-10*t)]; |
|
146 %! |
|
147 %! assert(all (all (abs (x - y) < tol))); |
|
148 |
|
149 %% test/octave.test/diffeq/dassl_options-1.m |
|
150 %!test |
|
151 %! dassl_options ("absolute tolerance", eps); |
|
152 %! assert(dassl_options ("absolute tolerance") == eps); |
|
153 |
|
154 %% test/octave.test/diffeq/dassl_options-3.m |
5751
|
155 %!error <Invalid call to dassl_options.*> dassl_options ("foo", 1, 2); |
5590
|
156 |