1
/* Test cases for ode1_riccati.mac functions
3
Do not kill(all); It messes up trigsimp */
5
/* Need these indentities to check solutions */
6
besjident(n,x):=bessel_j(n,x)=2*(n-1)*bessel_j(n-1,x)/x-bessel_j(n-2,x);
7
besjident(n,x):=bessel_j(n,x)=2*(n-1)*bessel_j(n-1,x)/x-bessel_j(n-2,x);
8
besiident(n,x):=bessel_i(n,x)=-2*(n-1)*bessel_i(n-1,x)/x+bessel_i(n-2,x);
9
besiident(n,x):=bessel_i(n,x)=-2*(n-1)*bessel_i(n-1,x)/x+bessel_i(n-2,x);
10
beskident(n,x):=bessel_k(n,x)=2*(n-1)*bessel_k(n-1,x)/x+bessel_k(n-2,x);
11
beskident(n,x):=bessel_k(n,x)=2*(n-1)*bessel_k(n-1,x)/x+bessel_k(n-2,x);
13
/* Test cases with n=2*a ode1_riccati_special(a,b,c,n,y,x)*/
14
eq:x*'diff(y,x)-a*y+b*y^2=c*x^n;
15
x*'diff(y,x)-a*y+b*y^2=c*x^n;
17
/* Case a.i.1 n=2*a, b>0, c>0 */
18
(print("Special Riccati equation: Case a.i.1: n=2*a, b>0, c>0"),done);
20
ans:ode1_riccati_special(a:1,b:1,c:1,n:2,y,x);
22
trigsimp(ode_check(eq,ans));
24
ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=x^2,y,x);
26
trigsimp(ode_check(eqn,ans));
28
ans:ode1_riccati_special(a:2,b:2,c:3,n:4,y,x);
29
y=sqrt(3)*x^2*tanh(sqrt(6)*x^2/2+%c)/sqrt(2);
30
trigsimp(ode_check(eq,ans));
32
ans:ode1_riccati_special(a:3,b:2,c:3,n:6,y,x);
33
y=sqrt(3)*x^3*tanh(sqrt(6)*x^3/3+%c)/sqrt(2);
34
trigsimp(ode_check(eq,ans));
36
ans:ode1_riccati_special(a:-1,b:2,c:3,n:-2,y,x);
37
y=-sqrt(3)*tanh(sqrt(6)/x-%c)/(sqrt(2)*x);
38
trigsimp(ode_check(eq,ans));
41
/* Case a.i.2 n=2*a, b<0, c<0 */
42
(print("Special Riccati equation: Case a.i.2: n=2*a, b<0, c<0"),done);
44
ans:ode1_riccati_special(a:1,b:-1,c:-1,n:2,y,x);
46
trigsimp(ode_check(eq,ans));
48
ans:ode1_riccati(eqn:x*'diff(y,x)-y-y^2=-x^2,y,x);
50
trigsimp(ode_check(eqn,ans));
52
ans:ode1_riccati_special(a:2,b:-2,c:-3,n:4,y,x);
53
y=-sqrt(3)*x^2*tanh(sqrt(6)*x^2/2-%c)/sqrt(2);
54
trigsimp(ode_check(eq,ans));
56
ans:ode1_riccati_special(a:3,b:-2,c:-3,n:6,y,x);
57
y=-sqrt(3)*x^3*tanh(sqrt(6)*x^3/3-%c)/sqrt(2);
58
trigsimp(ode_check(eq,ans));
60
ans:ode1_riccati_special(a:-1,b:-2,c:-3,n:-2,y,x);
61
y=sqrt(3)*tanh(sqrt(6)/x+%c)/(sqrt(2)*x);
62
trigsimp(ode_check(eq,ans));
65
/* Case a.i.3 n=2*a, b>0, c<0 */
66
(print("Special Riccati equation: Case a.i.3: n=2*a, b>0, c<0"),done);
68
ans:ode1_riccati_special(a:1,b:1,c:-1,n:2,y,x);
70
trigsimp(ode_check(eq,ans));
72
ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=-x^2,y,x);
74
trigsimp(ode_check(eqn,ans));
76
ans:ode1_riccati_special(a:2,b:2,c:-3,n:4,y,x);
77
y=-sqrt(3)*x^2*tan(sqrt(6)*x^2/2-%c)/sqrt(2);
78
trigsimp(ode_check(eq,ans));
80
ans:ode1_riccati_special(a:3,b:2,c:-3,n:6,y,x);
81
y=-sqrt(3)*x^3*tan(sqrt(6)*x^3/3-%c)/sqrt(2);
82
trigsimp(ode_check(eq,ans));
84
ans:ode1_riccati_special(a:-1,b:2,c:-3,n:-2,y,x);
85
y=sqrt(3)*tan(sqrt(6)/x+%c)/(sqrt(2)*x);
86
trigsimp(ode_check(eq,ans));
89
/* Case a.i.4 n=2*a, b<0, c>0 */
90
(print("Special Riccati equation: Case a.i.4: n=2*a, b<0, c>0"),done);
92
ans:ode1_riccati_special(a:1,b:-1,c:1,n:2,y,x);
94
trigsimp(ode_check(eq,ans));
96
ans:ode1_riccati(eqn:x*'diff(y,x)-y-y^2=x^2,y,x);
98
trigsimp(ode_check(eqn,ans));
100
ans:ode1_riccati_special(a:2,b:-2,c:3,n:4,y,x);
101
y=sqrt(3)*x^2*tan(sqrt(6)*x^2/2+%c)/sqrt(2);
102
trigsimp(ode_check(eq,ans));
104
ans:ode1_riccati_special(a:3,b:-2,c:3,n:6,y,x);
105
y=sqrt(3)*x^3*tan(sqrt(6)*x^3/3+%c)/sqrt(2);
106
trigsimp(ode_check(eq,ans));
108
ans:ode1_riccati_special(a:-1,b:-2,c:3,n:-2,y,x);
109
y=-sqrt(3)*tan(sqrt(6)/x-%c)/(sqrt(2)*x);
110
trigsimp(ode_check(eq,ans));
115
/* Check that the sign of b and c is handled correctly */
118
ode1_riccati_special(2,b,c,4,y,x);
119
y=sqrt(c)*x^2*tanh(sqrt(b)*sqrt(c)*x^2/2+%c)/sqrt(b);
120
ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
121
y=sqrt(c)*x^2*tanh(sqrt(b)*sqrt(c)*x^2/2+%c)/sqrt(b);
122
trigsimp(ode_check(eqn,ans));
129
ans:ode1_riccati_special(2,b,c,4,y,x);
130
y=-sqrt(-c)*x^2*tanh(sqrt(-b)*sqrt(-c)*x^2/2-%c)/sqrt(-b);
131
ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
132
y=-sqrt(-c)*x^2*tanh(sqrt(-b)*sqrt(-c)*x^2/2-%c)/sqrt(-b);
133
trigsimp(ode_check(eqn,ans));
140
ode1_riccati_special(2,b,c,4,y,x);
141
y=-sqrt(-c)*x^2*tan(sqrt(b)*sqrt(-c)*x^2/2-%c)/sqrt(b);
142
ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
143
y=-sqrt(-c)*x^2*tan(sqrt(b)*sqrt(-c)*x^2/2-%c)/sqrt(b);
144
trigsimp(ode_check(eqn,ans));
151
ode1_riccati_special(2,b,c,4,y,x);
152
y=sqrt(c)*x^2*tan(sqrt(-b)*sqrt(c)*x^2/2+%c)/sqrt(-b);
153
ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
154
y=sqrt(c)*x^2*tan(sqrt(-b)*sqrt(c)*x^2/2+%c)/sqrt(-b);
155
trigsimp(ode_check(eqn,ans));
160
/* Tests for ode1_riccati_special - Case ii: (n-2*a)/2n=k , positive integer */
162
ans:ode1_riccati_special(a:1,b:1,c:1,n:-2/3,y,x);
163
y=1/((1/3-1/(tanh(3/x^(1/3)-%c)*x^(1/3)))*x^(2/3))+1;
164
trigsimp(ode_check(eq,ans));
166
ans:ode1_riccati_special(a:2,b:1,c:1,n:-4/3,y,x);
167
y=1/((2/3-1/(tanh(3/(2*x^(2/3))-%c)*x^(2/3)))*x^(4/3))+2;
168
trigsimp(ode_check(eq,ans));
170
ans:ode1_riccati_special(a:-3/2,b:1,c:1,n:1,y,x);
171
y=x/(sqrt(x)/tanh(2*sqrt(x)+%c)-1/2)-3/2;
172
trigsimp(ode_check(eq,ans));
174
ans:ode1_riccati_special(a:3/2,b:1,c:1,n:-1,y,x);
175
y=1/((1/2-1/(tanh(2/sqrt(x)-%c)*sqrt(x)))*x)+3/2;
176
trigsimp(ode_check(eq,ans));
178
ans:ode1_riccati_special(a:-3/2,b:4,c:9,n:1,y,x);
179
y=x/(2*sqrt(x)/(3*tanh(12*sqrt(x)+%c))-1/18)-3/8;
180
trigsimp(ode_check(eq,ans));
183
/* Tests for ode1_riccati_special - Case iii: (n+2*a)/2n=k , positive integer */
185
ans:ode1_riccati_special(a:1,b:1,c:1,n:2/3,y,x);
186
y=x^(2/3)/(x^(1/3)/tanh(3*x^(1/3)+%c)-1/3);
187
trigsimp(ode_check(eq,ans));
189
ans:ode1_riccati_special(a:2,b:1,c:1,n:4/3,y,x);
190
y=x^(4/3)/(x^(2/3)/tanh(3*x^(2/3)/2+%c)-2/3);
191
trigsimp(ode_check(eq,ans));
193
ans:ode1_riccati_special(a:3/2,b:1,c:1,n:1,y,x);
194
y = x/(sqrt(x)/tanh(2*sqrt(x)+%c)-1/2);
195
trigsimp(ode_check(eq,ans));
197
ans:ode1_riccati_special(a:3,b:1,c:1,n:2,y,x);
198
y = x^2/(x/tanh(x+%c)-1);
199
trigsimp(ode_check(eq,ans));
201
ans:ode1_riccati_special(a:3,b:-9,c:4,n:2,y,x);
202
y=x^2/(3*x/(2*tan(6*x+%c))-1/4);
203
trigsimp(ode_check(eq,ans));
206
/* Tests for ode1_riccati_special - Case c: not integrable a#0 */
208
/* Bessel function of integer order - easy to check */
209
ans:ode1_riccati_special(a:1,b:-1,c:1,n:1,y,x);
210
y=-(bessel_y(0,2*sqrt(x))*%c+bessel_j(0,2*sqrt(x)))*sqrt(x)/(bessel_y(1,2*sqrt(x))*%c+bessel_j(1,2*sqrt(x)));
214
ans:ode1_riccati_special(a:1,b:-2,c:3,n:1,y,x);
215
y=-(sqrt(6)*bessel_y(0,2*sqrt(6)*sqrt(x))*%c+sqrt(6)*bessel_j(0,2*sqrt(6)*sqrt(x)))*sqrt(x)/(2*bessel_y(1,2*sqrt(6)*sqrt(x))*%c+2*bessel_j(1,2*sqrt(6)*sqrt(x)));
221
ans:ode1_riccati_special(a:2,b:-2,c:3,n:2,y,x);
222
y=-(sqrt(2)*sqrt(3)*bessel_y(0,2*sqrt(3)*x/sqrt(2))*%c+sqrt(2)*sqrt(3)*bessel_j(0,2*sqrt(3)*x/sqrt(2)))*x/(2*bessel_y(1,2*sqrt(3)*x/sqrt(2))*%c+2*bessel_j(1,2*sqrt(3)*x/sqrt(2)));
228
/* Cases that end up in ode1_riccati_original with m=-2 */
229
ans:ode1_riccati_special(a:1,b:-1,c:1,n:0,y,x);
230
y=-sqrt(x)*(sqrt(x)*(sqrt(3)*%c*cos(sqrt(3)*log(x)/2)/(2*x)-sqrt(3)*sin(sqrt(3)*log(x)/2)/(2*x))+(%c*sin(sqrt(3)*log(x)/2)+cos(sqrt(3)*log(x)/2))/(2*sqrt(x)))/(%c*sin(sqrt(3)*log(x)/2)+cos(sqrt(3)*log(x)/2));
234
ans:ode1_riccati_special(a:1,b:1,c:1,n:0,y,x);
235
y=sqrt(x)*((x^(sqrt(5)/2)+%c/x^(sqrt(5)/2))/(2*sqrt(x))+sqrt(x)*(sqrt(5)*x^(sqrt(5)/2-1)/2-sqrt(5)*%c*x^(-sqrt(5)/2-1)/2))/(x^(sqrt(5)/2)+%c/x^(sqrt(5)/2));
239
ans:ode1_riccati_special(a:1,b:-1/4,c:1,n:0,y,x);
240
y=-4*sqrt(x)*((%c*log(x)+1)/(2*sqrt(x))+%c/sqrt(x))/(%c*log(x)+1);
244
/* Cases with a=0 and b*c<0 */
245
ans:ode1_riccati_special(a:0,b:-1,c:1,n:2,y,x);
246
y=(bessel_y(1,x)*%c+bessel_j(1,x))*x/(bessel_y(0,x)*%c+bessel_j(0,x));
250
ans:ode1_riccati_special(a:0,b:-1,c:1,n:1,y,x);
251
y=(bessel_y(1,2*sqrt(x))*%c+bessel_j(1,2*sqrt(x)))*sqrt(x)/(bessel_y(0,2*sqrt(x))*%c+bessel_j(0,2*sqrt(x)));
255
/* Cases with a=0 and b*c>0 */
256
ans:ode1_riccati_special(a:0,b:1,c:1,n:2,y,x);
257
y=-(bessel_k(1,x)*%c-bessel_i(1,x))*x/(bessel_k(0,x)*%c+bessel_i(0,x));
261
ans:ode1_riccati_special(a:0,b:1,c:1,n:1,y,x);
262
y=-(bessel_k(1,2*sqrt(x))*%c-bessel_i(1,2*sqrt(x)))*sqrt(x)/(bessel_k(0,2*sqrt(x))*%c+bessel_i(0,2*sqrt(x)));
269
/* some tests for ode1_riccati_original */
270
eqn:'diff(y,x)+b*y^2=c*x^m;
271
'diff(y,x)+b*y^2=c*x^m;
272
/* Case m*(2*k+1)+4*k=0 and k=0 => m=0
273
also m*(2*k-1)+4*k=0 and k=0 => m=0 */
274
ans:ode1_riccati_original(b:4,c:1,m:0,y,x);
276
trigsimp(ode_check(eqn,ans));
278
ans:ode1_riccati_original(b:-4,c:1,m:0,y,x);
280
trigsimp(ode_check(eqn,ans));
282
ans:ode1_riccati_original(b:4,c:-1,m:0,y,x);
284
trigsimp(ode_check(eqn,ans));
286
ans:ode1_riccati_original(b:-4,c:-1,m:0,y,x);
288
trigsimp(ode_check(eqn,ans));
291
/* Case m*(2*k+1)+4*k=0, k positive integer */
293
ans:ode1_riccati_original(b:1,c:1,m:-4/3,y,x);
294
y=3*tanh(3*x^(1/3)+%c)/(3*x^(2/3)-tanh(3*x^(1/3)+%c)*x^(1/3));
295
trigsimp(ode_check(eqn,ans));
298
ans:ode1_riccati_original(b:-1,c:1,m:-8/5,y,x);
299
y=-(25*x^(1/5)-5*tan(5*x^(1/5)-%c))/(25*tan(5*x^(1/5)-%c)*x+15*x^(4/5)-3*tan(5*x^(1/5)-%c)*x^(3/5));
300
/* This is correct - checking takes too long for testsuite */
302
ans:ode1_riccati_original(b:1,c:1,m:-12/7,y,x);
303
y=(343*tanh(7*x^(1/7)+%c)*x^(2/7)-147*x^(1/7)+21*tanh(7*x^(1/7)+%c))/(343*x^(8/7)-294*tanh(7*x^(1/7)+%c)*x+105*x^(6/7)-15*tanh(7*x^(1/7)+%C)*x^(5/7));
304
/* This is correct - checking takes too long for testsuite */
306
/* Case m*(2*k-1)+4*k=0, k positive integer */
308
ans:ode1_riccati_original(b:1,c:1,m:-4,y,x);
309
y=(x*tanh((%c*x-1)/x)+1)/(x^2*tanh((%c*x-1)/x));
310
trigsimp(ode_check(eqn,ans));
313
ans:ode1_riccati_original(b:1,c:1,m:-8/3,y,x);
314
y=(tanh((%c*x^(1/3)-3)/x^(1/3))*x+3*x^(2/3)+3*tanh((%c*x^(1/3)-3)/x^(1/3))*x^(1/3))/(tanh((%c*x^(1/3)-3)/x^(1/3))*x^2+3*x^(5/3));
315
ode_check(eqn,ratsimp(exponentialize(ans)));
318
ans:ode1_riccati_original(b:1,c:1,m:-12/5,y,x);
319
y=(3*tanh((%c*x^(1/5)-5)/x^(1/5))*x^(3/5)+15*x^(2/5)+30*tanh((%c*x^(1/5)-5)/x^(1/5))*x^(1/5)+25)/(3*tanh((%c*x^(1/5)-5)/x^(1/5))*x^(8/5)+15*x^(7/5)+25*tanh((%c*x^(1/5)-5)/x^(1/5))*x^(6/5));
320
/* ode_check(eqn,ratsimp(exponentialize(ans)));
323
ans:ode1_riccati_original(b:1,c:1,m:-16/7,y,x);
324
y=(15*tanh((%c*x^(1/7)-7)/x^(1/7))*x^(4/7)+105*x^(3/7)+315*tanh((%c*x^(1/7)-7)/x^(1/7))*x^(2/7)+490*x^(1/7)+343*tanh((%c*x^(1/7)-7)/x^(1/7)))/(15*tanh((%c*x^(1/7)-7)/x^(1/7))*x^(11/7)+105*x^(10/7)+294*tanh((%c*x^(1/7)-7)/x^(1/7))*x^(9/7)+343*x^(8/7));
325
/* ode_check(eqn,ratsimp(exponentialize(ans)));
328
/* Bessel function solution - integer order with b*c<0 */
329
ans:ode1_riccati_original(b:3,c:-2,m:-1,y,x);
330
y=(sqrt(6)*bessel_y(0,2*sqrt(6)*sqrt(x))*%c+sqrt(6)*bessel_j(0,2*sqrt(6)*sqrt(x)))/((3*bessel_y(1,2*sqrt(6)*sqrt(x))*%c+3*bessel_j(1,2*sqrt(6)*sqrt(x)))*sqrt(x));
334
/* Bessel function solution - integer order with b*c>0 */
337
ans:ode1_riccati_original(b:3,c:2,m:-1,y,x);
338
y=-(sqrt(6)*bessel_k(0,2*sqrt(6)*sqrt(x))*%c-sqrt(6)*bessel_i(0,2*sqrt(6)*sqrt(x)))/((3*bessel_k(1,2*sqrt(6)*sqrt(x))*%c+3*bessel_i(1,2*sqrt(6)*sqrt(x)))*sqrt(x));
344
/* Bessel function solution - non-integer order b*c<0 */
345
ans:ode1_riccati_original(b:1,c:-1,m:2,y,x);
346
y=((bessel_j(-5/4,x^2/2)*%c+bessel_j(-3/4,x^2/2))*x^2+bessel_j(-1/4,x^2/2)*%c)/((bessel_j(-1/4,x^2/2)*%c+bessel_j(1/4,x^2/2))*x);
348
(((bessel_j(-1/4,x^2/2)+bessel_j(-9/4,x^2/2))*%c+bessel_j(1/4,x^2/2)+bessel_j(-7/4,x^2/2))*x^2+5*bessel_j(-5/4,x^2/2)*%c+3*bessel_j(-3/4,x^2/2))/(bessel_j(-1/4,x^2/2)*%c+bessel_j(1/4,x^2/2));
349
expand(ev(%,besjident(1/4,x^2/2),besjident(-1/4,x^2/2)));
352
/* Bessel function solution - non-integer order b*c>0 */
355
ans:ode1_riccati_original(b:2,c:3,m:-5,y,x);
356
y=-((sqrt(6)*bessel_k(-2/3,-2*sqrt(6)/(3*x^(3/2)))*%c-sqrt(6)*bessel_i(-4/3,-2*sqrt(6)/(3*x^(3/2))))*sqrt(x)-bessel_k(1/3,-2*sqrt(6)/(3*x^(3/2)))*%c*x^2)/((2*bessel_k(1/3,-2*sqrt(6)/(3*x^(3/2)))*%c+2*bessel_i(-1/3,-2*sqrt(6)/(3*x^(3/2))))*x^3);
358
((6*bessel_k(-2/3,-2*sqrt(6)/(3*x^(3/2)))*%c-12*bessel_i(-4/3,-2*sqrt(6)/(3*x^(3/2))))*x^(3/2)+(3*sqrt(6)*bessel_k(-5/3,-2*sqrt(6)/(3*x^(3/2)))-3*sqrt(6)*bessel_k(1/3,-2*sqrt(6)/(3*x^(3/2))))*%c-3*sqrt(6)*bessel_i(-1/3,-2*sqrt(6)/(3*x^(3/2)))+3*sqrt(6)*bessel_i(-7/3,-2*sqrt(6)/(3*x^(3/2))))/((sqrt(6)*bessel_k(1/3,-2*sqrt(6)/(3*x^(3/2)))*%c+sqrt(6)*bessel_i(-1/3,-2*sqrt(6)/(3*x^(3/2))))*x^5);
359
expand(ev(%,besiident(-1/3,-2*sqrt(6)/(3*x^(3/2))),beskident(1/3,-2*sqrt(6)/(3*x^(3/2)))));
364
/* Original Riccati equation: m=-2 Case i */
365
ans:ode1_riccati_original(b:2,c:-3,m:-2,y,x);
366
y=(sqrt(x)*(sqrt(23)*%c*cos(sqrt(23)*log(x)/2)/(2*x)-sqrt(23)*sin(sqrt(23)*log(x)/2)/(2*x))+(%c*sin(sqrt(23)*log(x)/2)+cos(sqrt(23)*log(x)/2))/(2*sqrt(x)))/(2*sqrt(x)*(%c*sin(sqrt(23)*log(x)/2)+cos(sqrt(23)*log(x)/2)));
370
/* Original Riccati equation: m=-2 Case ii */
371
ans:ode1_riccati_original(b:2,c:3,m:-2,y,x);
372
y=((x^(5/2)+%c/x^(5/2))/(2*sqrt(x))+sqrt(x)*(5*x^(3/2)/2-5*%c/(2*x^(7/2))))/(2*sqrt(x)*(x^(5/2)+%c/x^(5/2)));
376
/* Original Riccati equation: m=-2 Case iii */
377
ans:ode1_riccati_original(b:1,c:-1/4,m:-2,y,x);
378
y=((%c*log(x)+1)/(2*sqrt(x))+%c/sqrt(x))/(sqrt(x)*(%c*log(x)+1));
385
/* Murphy 249 (3-3) */
386
ans:contrib_ode(eqn:3*x*'diff(y,x)=3*x^(2/3)+(1-3*y)*y,y,x);
387
[y=tanh(3*x^(1/3)+%c)*x^(1/3)];
388
trigsimp(ode_check(eqn,ans[1]));
391
/* murphy 373 (3-2) */
394
ans:ode1_riccati(eqn:x^4*'diff(y,x)+a^2+x^4*y^2=0,y,x);
395
y=(x*TAN((%C*x-a)/x)+a)/(x^2*TAN((%C*x-a)/x));
396
trigsimp(ode_check(eqn,ans));
401
/* Murphy 168 - Case (a.iii) with k = 2 */
402
ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=x^(2/3),y,x);
403
y=x^(2/3)/(x^(1/3)/tanh(3*x^(1/3)+%c)-1/3);
404
trigsimp(ode_check(eqn,ans));