1 (load("contrib_ode"),0);
4 /* Test cases for ode1_riccati.mac functions */
6 /* Test cases with n=2*a ode1_riccati_special(a,b,c,n,y,x)*/
7 eq:x*'diff(y,x)-a*y+b*y^2=c*x^n;
8 x*'diff(y,x)-a*y+b*y^2=c*x^n;
10 /* Case a.i.1 n=2*a, b>0, c>0 */
11 (print("Special Riccati equation: Case a.i.1: n=2*a, b>0, c>0"),done);
13 ans:ode1_riccati_special(a:1,b:1,c:1,n:2,y,x);
17 ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=x^2,y,x);
21 ans:ode1_riccati_special(a:2,b:2,c:3,n:4,y,x);
22 y=sqrt(3)*x^2*tanh(sqrt(6)*x^2/2+%c)/sqrt(2);
23 radcan(ode_check(eq,ans));
25 ans:ode1_riccati_special(a:3,b:2,c:3,n:6,y,x);
26 y=sqrt(3)*x^3*tanh(sqrt(6)*x^3/3+%c)/sqrt(2);
27 radcan(ode_check(eq,ans));
29 ans:ode1_riccati_special(a:-1,b:2,c:3,n:-2,y,x);
30 y=-sqrt(3)*tanh(sqrt(6)/x-%c)/(sqrt(2)*x);
31 radcan(ode_check(eq,ans));
34 /* Case a.i.2 n=2*a, b<0, c<0 */
35 (print("Special Riccati equation: Case a.i.2: n=2*a, b<0, c<0"),done);
37 ans:ode1_riccati_special(a:1,b:-1,c:-1,n:2,y,x);
41 ans:ode1_riccati(eqn:x*'diff(y,x)-y-y^2=-x^2,y,x);
45 ans:ode1_riccati_special(a:2,b:-2,c:-3,n:4,y,x);
46 y=-sqrt(3)*x^2*tanh(sqrt(6)*x^2/2-%c)/sqrt(2);
47 radcan(ode_check(eq,ans));
49 ans:ode1_riccati_special(a:3,b:-2,c:-3,n:6,y,x);
50 y=-sqrt(3)*x^3*tanh(sqrt(6)*x^3/3-%c)/sqrt(2);
51 radcan(ode_check(eq,ans));
53 ans:ode1_riccati_special(a:-1,b:-2,c:-3,n:-2,y,x);
54 y=sqrt(3)*tanh(sqrt(6)/x+%c)/(sqrt(2)*x);
55 radcan(ode_check(eq,ans));
58 /* Case a.i.3 n=2*a, b>0, c<0 */
59 (print("Special Riccati equation: Case a.i.3: n=2*a, b>0, c<0"),done);
61 ans:ode1_riccati_special(a:1,b:1,c:-1,n:2,y,x);
63 trigsimp(ode_check(eq,ans));
65 ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=-x^2,y,x);
67 trigsimp(ode_check(eqn,ans));
69 ans:ode1_riccati_special(a:2,b:2,c:-3,n:4,y,x);
70 y=-sqrt(3)*x^2*tan(sqrt(6)*x^2/2-%c)/sqrt(2);
71 radcan(trigsimp(ode_check(eq,ans)));
73 ans:ode1_riccati_special(a:3,b:2,c:-3,n:6,y,x);
74 y=-sqrt(3)*x^3*tan(sqrt(6)*x^3/3-%c)/sqrt(2);
75 radcan(ode_check(eq,ans));
77 ans:ode1_riccati_special(a:-1,b:2,c:-3,n:-2,y,x);
78 y=sqrt(3)*tan(sqrt(6)/x+%c)/(sqrt(2)*x);
79 radcan(ode_check(eq,ans));
82 /* Case a.i.4 n=2*a, b<0, c>0 */
83 (print("Special Riccati equation: Case a.i.4: n=2*a, b<0, c>0"),done);
85 ans:ode1_riccati_special(a:1,b:-1,c:1,n:2,y,x);
89 ans:ode1_riccati(eqn:x*'diff(y,x)-y-y^2=x^2,y,x);
93 ans:ode1_riccati_special(a:2,b:-2,c:3,n:4,y,x);
94 y=sqrt(3)*x^2*tan(sqrt(6)*x^2/2+%c)/sqrt(2);
95 radcan(ode_check(eq,ans));
97 ans:ode1_riccati_special(a:3,b:-2,c:3,n:6,y,x);
98 y=sqrt(3)*x^3*tan(sqrt(6)*x^3/3+%c)/sqrt(2);
99 radcan(ode_check(eq,ans));
101 ans:ode1_riccati_special(a:-1,b:-2,c:3,n:-2,y,x);
102 y=-sqrt(3)*tan(sqrt(6)/x-%c)/(sqrt(2)*x);
103 radcan(ode_check(eq,ans));
108 /* Check that the sign of b and c is handled correctly */
111 ode1_riccati_special(2,b,c,4,y,x);
112 y=sqrt(c)*x^2*tanh(sqrt(b)*sqrt(c)*x^2/2+%c)/sqrt(b);
113 ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
114 y=sqrt(c)*x^2*tanh(sqrt(b)*sqrt(c)*x^2/2+%c)/sqrt(b);
122 ans:ode1_riccati_special(2,b,c,4,y,x);
123 y=-sqrt(-c)*x^2*tanh(sqrt(-b)*sqrt(-c)*x^2/2-%c)/sqrt(-b);
124 ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
125 y=-sqrt(-c)*x^2*tanh(sqrt(-b)*sqrt(-c)*x^2/2-%c)/sqrt(-b);
133 ode1_riccati_special(2,b,c,4,y,x);
134 y=-sqrt(-c)*x^2*tan(sqrt(b)*sqrt(-c)*x^2/2-%c)/sqrt(b);
135 ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
136 y=-sqrt(-c)*x^2*tan(sqrt(b)*sqrt(-c)*x^2/2-%c)/sqrt(b);
144 ode1_riccati_special(2,b,c,4,y,x);
145 y=sqrt(c)*x^2*tan(sqrt(-b)*sqrt(c)*x^2/2+%c)/sqrt(-b);
146 ans:ode1_riccati(eqn:x*'diff(y,x)-2*y+b*y^2=c*x^4,y,x);
147 y=sqrt(c)*x^2*tan(sqrt(-b)*sqrt(c)*x^2/2+%c)/sqrt(-b);
153 /* Tests for ode1_riccati_special - Case ii: (n-2*a)/2n=k , positive integer */
155 ans:ode1_riccati_special(a:1,b:1,c:1,n:-2/3,y,x);
156 y=1/((1/3-1/(tanh(3/x^(1/3)-%c)*x^(1/3)))*x^(2/3))+1;
159 ans:ode1_riccati_special(a:2,b:1,c:1,n:-4/3,y,x);
160 y=1/((2/3-1/(tanh(3/(2*x^(2/3))-%c)*x^(2/3)))*x^(4/3))+2;
163 ans:ode1_riccati_special(a:-3/2,b:1,c:1,n:1,y,x);
164 y=x/(sqrt(x)/tanh(2*sqrt(x)+%c)-1/2)-3/2;
167 ans:ode1_riccati_special(a:3/2,b:1,c:1,n:-1,y,x);
168 y=1/((1/2-1/(tanh(2/sqrt(x)-%c)*sqrt(x)))*x)+3/2;
171 ans:ode1_riccati_special(a:-3/2,b:4,c:9,n:1,y,x);
172 y=x/(2*sqrt(x)/(3*tanh(12*sqrt(x)+%c))-1/18)-3/8;
176 /* Tests for ode1_riccati_special - Case iii: (n+2*a)/2n=k , positive integer */
178 ans:ode1_riccati_special(a:1,b:1,c:1,n:2/3,y,x);
179 y=x^(2/3)/(x^(1/3)/tanh(3*x^(1/3)+%c)-1/3);
182 ans:ode1_riccati_special(a:2,b:1,c:1,n:4/3,y,x);
183 y=x^(4/3)/(x^(2/3)/tanh(3*x^(2/3)/2+%c)-2/3);
186 ans:ode1_riccati_special(a:3/2,b:1,c:1,n:1,y,x);
187 y = x/(sqrt(x)/tanh(2*sqrt(x)+%c)-1/2);
190 ans:ode1_riccati_special(a:3,b:1,c:1,n:2,y,x);
191 y = x^2/(x/tanh(x+%c)-1);
194 ans:ode1_riccati_special(a:3,b:-9,c:4,n:2,y,x);
195 y=x^2/(3*x/(2*tan(6*x+%c))-1/4);
199 /* Tests for ode1_riccati_special - Case c: not integrable a#0 */
201 /* Bessel function of integer order - easy to check */
202 ans:ode1_riccati_special(a:1,b:-1,c:1,n:1,y,x);
203 y=(((bessel_y(2,2*sqrt(x))-bessel_y(0,2*sqrt(x)))*%c
204 +bessel_j(2,2*sqrt(x))-bessel_j(0,2*sqrt(x)))*sqrt(x)
205 -bessel_y(1,2*sqrt(x))*%c-bessel_j(1,2*sqrt(x)))
206 /(2*bessel_y(1,2*sqrt(x))*%c+2*bessel_j(1,2*sqrt(x)));
210 ans:ode1_riccati_special(a:1,b:-2,c:3,n:1,y,x);
211 y = (((sqrt(6)*bessel_y(2,2*sqrt(6)*sqrt(x))
212 -sqrt(6)*bessel_y(0,2*sqrt(6)*sqrt(x)))
214 +sqrt(6)*bessel_j(2,2*sqrt(6)*sqrt(x))
215 -sqrt(6)*bessel_j(0,2*sqrt(6)*sqrt(x)))
217 -bessel_y(1,2*sqrt(6)*sqrt(x))*%c-bessel_j(1,2*sqrt(6)*sqrt(x)))
218 /(4*bessel_y(1,2*sqrt(6)*sqrt(x))*%c
219 +4*bessel_j(1,2*sqrt(6)*sqrt(x)));
225 ans:ode1_riccati_special(a:2,b:-2,c:3,n:2,y,x);
226 y = (((sqrt(2)*sqrt(3)*bessel_y(2,2*sqrt(3)*x/sqrt(2))
227 -sqrt(2)*sqrt(3)*bessel_y(0,2*sqrt(3)*x/sqrt(2)))*%c
228 +sqrt(2)*sqrt(3)*bessel_j(2,2*sqrt(3)*x/sqrt(2))
229 -sqrt(2)*sqrt(3)*bessel_j(0,2*sqrt(3)*x/sqrt(2)))*x
230 -2*bessel_y(1,2*sqrt(3)*x/sqrt(2))*%c
231 -2*bessel_j(1,2*sqrt(3)*x/sqrt(2)))
232 /(4*bessel_y(1,2*sqrt(3)*x/sqrt(2))*%c+4*bessel_j(1,2*sqrt(3)*x/sqrt(2)));
238 /* Cases that end up in ode1_riccati_original with m=-2 */
239 ans:ode1_riccati_special(a:1,b:-1,c:1,n:0,y,x);
240 y = -(((%c-sqrt(3))*sin(sqrt(3)*log(x)/2)+(sqrt(3)*%c+1)*cos(sqrt(3)*log(x)/2))
241 /(2*%c*sin(sqrt(3)*log(x)/2)+2*cos(sqrt(3)*log(x)/2)));
245 ans:ode1_riccati_special(a:1,b:1,c:1,n:0,y,x);
246 y=((sqrt(5)+1)*x^sqrt(5)+(1-sqrt(5))*%c)/(2*x^sqrt(5)+2*%c);
250 ans:ode1_riccati_special(a:1,b:-1/4,c:1,n:0,y,x);
251 y=-((2*%c*log(x)+4*%c+2)/(%c*log(x)+1));
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_y(1,x)*%c+bessel_j(1,x))*x/(bessel_y(0,x)*%c+bessel_j(0,x));
261 ans:ode1_riccati_special(a:0,b:-1,c:1,n:1,y,x);
262 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)));
266 /* Cases with a=0 and b*c>0 */
267 ans:ode1_riccati_special(a:0,b:1,c:1,n:2,y,x);
268 y=-((bessel_k(1,x)*%c-bessel_i(1,x))*x/(bessel_k(0,x)*%c+bessel_i(0,x)));
272 ans:ode1_riccati_special(a:0,b:1,c:1,n:1,y,x);
273 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))));
280 /* some tests for ode1_riccati_original */
281 eqn:'diff(y,x)+b*y^2=c*x^m;
282 'diff(y,x)+b*y^2=c*x^m;
283 /* Case m*(2*k+1)+4*k=0 and k=0 => m=0
284 also m*(2*k-1)+4*k=0 and k=0 => m=0 */
285 ans:ode1_riccati_original(b:4,c:1,m:0,y,x);
289 ans:ode1_riccati_original(b:-4,c:1,m:0,y,x);
293 ans:ode1_riccati_original(b:4,c:-1,m:0,y,x);
297 ans:ode1_riccati_original(b:-4,c:-1,m:0,y,x);
302 /* Case m*(2*k+1)+4*k=0, k positive integer */
304 ans:ode1_riccati_original(b:1,c:1,m:-4/3,y,x);
305 y=3*tanh(3*x^(1/3)+%c)/(3*x^(2/3)-tanh(3*x^(1/3)+%c)*x^(1/3));
309 ans:ode1_riccati_original(b:-1,c:1,m:-8/5,y,x);
310 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)));
311 /* This is correct - checking takes too long for testsuite */
313 ans:ode1_riccati_original(b:1,c:1,m:-12/7,y,x);
314 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));
315 /* This is correct - checking takes too long for testsuite */
317 /* Case m*(2*k-1)+4*k=0, k positive integer */
319 ans:ode1_riccati_original(b:1,c:1,m:-4,y,x);
320 y=(x*tanh((%c*x-1)/x)+1)/(x^2*tanh((%c*x-1)/x));
324 ans:ode1_riccati_original(b:1,c:1,m:-8/3,y,x);
325 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));
326 ode_check(eqn,ratsimp(exponentialize(ans)));
329 ans:ode1_riccati_original(b:1,c:1,m:-12/5,y,x);
330 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));
331 /* ode_check(eqn,ratsimp(exponentialize(ans)));
334 ans:ode1_riccati_original(b:1,c:1,m:-16/7,y,x);
335 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));
336 /* ode_check(eqn,ratsimp(exponentialize(ans)));
339 /* Bessel function solution - integer order with b*c<0 */
340 ans:ode1_riccati_original(b:3,c:-2,m:-1,y,x);
341 y = -((((sqrt(6)*bessel_y(2,2*sqrt(6)*sqrt(x))
342 -sqrt(6)*bessel_y(0,2*sqrt(6)*sqrt(x)))*%c
343 +sqrt(6)*bessel_j(2,2*sqrt(6)*sqrt(x))
344 -sqrt(6)*bessel_j(0,2*sqrt(6)*sqrt(x)))*sqrt(x)
345 -bessel_y(1,2*sqrt(6)*sqrt(x))*%c-bessel_j(1,2*sqrt(6)*sqrt(x)))
346 /((6*bessel_y(1,2*sqrt(6)*sqrt(x))*%c+6*bessel_j(1,2*sqrt(6)*sqrt(x)))*x));
350 /* Bessel function solution - integer order with b*c>0 */
353 ans:ode1_riccati_original(b:3,c:2,m:-1,y,x);
354 y = -((((sqrt(6)*bessel_k(2,2*sqrt(6)*sqrt(x))
355 +sqrt(6)*bessel_k(0,2*sqrt(6)*sqrt(x)))*%c
356 -sqrt(6)*bessel_i(2,2*sqrt(6)*sqrt(x))
357 -sqrt(6)*bessel_i(0,2*sqrt(6)*sqrt(x)))*sqrt(x)
358 -bessel_k(1,2*sqrt(6)*sqrt(x))*%c-bessel_i(1,2*sqrt(6)*sqrt(x)))
359 /((6*bessel_k(1,2*sqrt(6)*sqrt(x))*%c
360 +6*bessel_i(1,2*sqrt(6)*sqrt(x)))*x));
366 /* Bessel function solution - non-integer order b*c<0 */
367 ans:ode1_riccati_original(b:1,c:-1,m:2,y,x);
368 y = -((((bessel_j(3/4,x^2/2)-bessel_j(-5/4,x^2/2))*%c
369 +bessel_j(5/4,x^2/2)-bessel_j(-3/4,x^2/2))*x^2
370 -bessel_j(-1/4,x^2/2)*%c-bessel_j(1/4,x^2/2))
371 /((2*bessel_j(-1/4,x^2/2)*%c+2*bessel_j(1/4,x^2/2))*x));
375 /* Bessel function solution - non-integer order b*c>0 */
378 ans:ode1_riccati_original(b:2,c:3,m:-5,y,x);
379 y = -(((-bessel_k(1/3,-(2*sqrt(6))/(3*x^(3/2)))*%c)
380 -bessel_i(-1/3,-(2*sqrt(6))/(3*x^(3/2))))
382 +((sqrt(6)*bessel_k(4/3,-(2*sqrt(6))/(3*x^(3/2)))
383 +sqrt(6)*bessel_k(2/3,-(2*sqrt(6))/(3*x^(3/2))))
385 -sqrt(6)*bessel_i(2/3,-(2*sqrt(6))/(3*x^(3/2)))
386 -sqrt(6)*bessel_i(-4/3,-(2*sqrt(6))/(3*x^(3/2))))
388 /((4*bessel_k(1/3,-(2*sqrt(6))/(3*x^(3/2)))*%c
389 +4*bessel_i(-1/3,-(2*sqrt(6))/(3*x^(3/2))))
396 /* Original Riccati equation: m=-2 Case i */
397 ans:ode1_riccati_original(b:2,c:-3,m:-2,y,x);
398 y=((%c-sqrt(23))*sin(sqrt(23)*log(x)/2)+(sqrt(23)*%c+1)*cos(sqrt(23)*log(x)/2))
399 /(4*%c*x*sin(sqrt(23)*log(x)/2)+4*x*cos(sqrt(23)*log(x)/2));
403 /* Original Riccati equation: m=-2 Case ii */
404 ans:ode1_riccati_original(b:2,c:3,m:-2,y,x);
405 y=(3*x^5-2*%c)/(2*x^6+2*%c*x);
409 /* Original Riccati equation: m=-2 Case iii */
410 ans:ode1_riccati_original(b:1,c:-1/4,m:-2,y,x);
411 y=(%c*log(x)+2*%c+1)/(2*%c*x*log(x)+2*x);
418 /* Murphy 249 (3-3) */
419 ans:contrib_ode(eqn:3*x*'diff(y,x)=3*x^(2/3)+(1-3*y)*y,y,x);
420 [y=tanh(3*x^(1/3)+%c)*x^(1/3)];
421 ode_check(eqn,ans[1]);
424 /* murphy 373 (3-2) */
427 ans:ode1_riccati(eqn:x^4*'diff(y,x)+a^2+x^4*y^2=0,y,x);
428 y=(x*tan((%c*x-a)/x)+a)/(x^2*tan((%c*x-a)/x));
434 /* Murphy 168 - Case (a.iii) with k = 2 */
435 ans:ode1_riccati(eqn:x*'diff(y,x)-y+y^2=x^(2/3),y,x);
436 y=x^(2/3)/(x^(1/3)/tanh(3*x^(1/3)+%c)-1/3);