1 (load("contrib_ode"),0);
4 /* ODE tests - Murphy equations 1.1 - 1.100
7 G M Murphy, Ordinary Differential Equations and Their
8 Solutions, Van Nostrand, 1960
10 First Order and of First Degree, p 224 ff
13 /* Don't kill(all); It messes up trigsimp */
16 (pn_(n_):=print("Murphy ODE 1.",n_),true);
20 (pn_(1),ans:contrib_ode(eqn:'diff(y,x)=a*f(x),y,x));
21 [y=a*'integrate(f(x),x)+%c];
22 [method,ode_check(eqn,ans[1])];
26 (pn_(2),ans:contrib_ode(eqn:'diff(y,x)=x+sin(x)+y,y,x));
27 [y = %e^x*(%e^-x*(-sin(x)-cos(x))/2+(-x-1)*%e^-x+%c)];
28 [method,ode_check(eqn,ans[1])];
32 (pn_(3),ans:contrib_ode(eqn:'diff(y,x)=x^2+3*cosh(x)+2*y,y,x),0);
35 y = %c*%e^(2*x)-3*%e^x/2-%e^-x/2-x^2/2-x/2-1/4;
36 [method,ode_check(eqn,ans)];
40 (pn_(4),ans:contrib_ode(eqn:'diff(y,x)=a+b*x+c*y,y,x));
41 [y=(-b*(c*x+1)*%e^-(c*x)/c^2-a*%e^-(c*x)/c+%c)*%e^(c*x)];
42 [method,ode_check(eqn,ans[1])];
46 (pn_(5),ans:contrib_ode(eqn:'diff(y,x)=a*cos(b*x+c)+k*y,y,x));
47 [y=%e^(k*x)*(a*%e^-(k*x)*(b*sin(b*x+c)-k*cos(b*x+c))/(k^2+b^2)+%c)];
48 [method,ode_check(eqn,ans[1])];
52 (pn_(6),ans:contrib_ode(eqn:'diff(y,x)=a*sin(b*x+c)+k*y,y,x));
53 [y=%e^(k*x)*(a*%e^-(k*x)*(-k*sin(b*x+c)-b*cos(b*x+c))/(k^2+b^2)+%c)];
54 [method,ode_check(eqn,ans[1])];
58 (pn_(7),assume(c>0,k>c),ans:contrib_ode(eqn:'diff(y,x)=a+b*exp(k*x)+c*y,y,x),forget(c>0,k>c),0);
61 y = (-(b*%e^(k*x))/(c-k))+%c*%e^(c*x)-a/c$
62 [method,ode_check(eqn,ans[1])];
66 (pn_(8),ans:contrib_ode(eqn:'diff(y,x)=x*(x^2-2*y),y,x));
67 [y = %e^-x^2*((x^2-1)*%e^x^2/2+%c)];
68 [method,ode_check(eqn,ans[1])];
71 /* 9 NOTE: Case a=2 is special */
72 (pn_(9),ans:contrib_ode(eqn:'diff(y,x)=x*(exp(-x^2)-a*y),y,x));
73 [y = %e^-(a*x^2/2)*(%e^(a*x^2/2-x^2)/(a-2)+%c)];
74 [method,ode_check(eqn,ans[1])];
77 ans:contrib_ode(eqn:'diff(y,x)=x*(exp(-x^2)-2*y),y,x);
78 [y=(x^2/2+%c)*%e^-x^2];
79 [method,ode_check(eqn,ans[1])];
83 (pn_(10),ans:contrib_ode(eqn:'diff(y,x)=x^2*(a*x^3+b*y),y,x));
84 [y = (%c-a*(3*b*x^3+9)*%e^-(b*x^3/3)/(3*b^2))*%e^(b*x^3/3)];
85 [method,ode_check(eqn,ans[1])];
89 (pn_(11),assume(not equal(n,-1)),ans:contrib_ode(eqn:'diff(y,x)=a*x^n*y,y,x),forget(not equal(n,-1)),ans);
90 [y = %c*%e^(a*x^(n+1)/(n+1))];
91 [method,ode_check(eqn,ans[1])];
95 ans:contrib_ode(eqn:'diff(y,x)=a*x^-1*y,y,x);
96 [y = %c*%e^(a*log(x))];
97 [method,ode_check(eqn,ans[1])];
101 (pn_(12),ans:contrib_ode(eqn:'diff(y,x)=cos(x)*sin(x)+y*cos(x),y,x));
102 [y = (%e^-sin(x)*(-sin(x)-1)+%c)*%e^sin(x)];
104 y = %c*%e^sin(x)-sin(x)-1;
105 [method,ode_check(eqn,ans)];
109 (pn_(13),ans:contrib_ode(eqn:'diff(y,x)=exp(sin(x))+y*cos(x),y,x));
110 [y = (x+%c)*%e^sin(x)];
111 [method,ode_check(eqn,ans[1])];
115 (pn_(14),ans:contrib_ode(eqn:'diff(y,x)=y*cot(x),y,x));
117 [method,ode_check(eqn,ans[1])];
121 (pn_(15),ans:contrib_ode(eqn:'diff(y,x)=1-y*cot(x),y,x));
122 [y = (%c-cos(x))/sin(x)];
123 [method,ode_check(eqn,ans[1])];
127 (pn_(16),ans:contrib_ode(eqn:'diff(y,x)=x*csc(x)-y*cot(x),y,x));
128 [y = (x^2/2+%c)/sin(x)];
129 [method,ode_check(eqn,ans[1])];
133 (pn_(17),ans:contrib_ode(eqn:'diff(y,x)=(2*csc(2*x)+cot(x))*y,y,x));
134 [y = %c*sin(x)/(csc(2*x)+cot(2*x))];
135 [method,ode_check(eqn,ans[1])];
139 (pn_(18),ans:contrib_ode(eqn:'diff(y,x)=sec(x)-y*cot(x),y,x));
140 [y = (%c-log(1-sin(x)^2)/2)/sin(x)];
141 ans:subst(cos(x)^2,1-sin(x)^2,ans[1]);
142 y = (%c-log(cos(x)))/sin(x);
143 [method,ode_check(eqn,ans)];
147 (pn_(19),ans:contrib_ode(eqn:'diff(y,x)=exp(x)*sin(x)+y*cot(x),y,x));
148 [y = (%e^x+%c)*sin(x)];
149 [method,ode_check(eqn,ans[1])];
153 (pn_(20),ans:contrib_ode(eqn:'diff(y,x)+csc(x)+2*y*cot(x)=0,y,x));
154 [y = (cos(x)+%c)/sin(x)^2];
155 [method,ode_check(eqn,ans[1])];
159 (pn_(21),ans:contrib_ode(eqn:'diff(y,x)=2*csc(2*x)*sec(x)^2-2*y*cot(2*x),y,x));
160 [y=(4*sin(2*x)/(sin(2*x)^2+cos(2*x)^2+2*cos(2*x)+1)+%c)/sin(2*x)];
161 [method,ode_check(eqn,ans[1])];
165 (pn_(22),ans:contrib_ode(eqn:'diff(y,x)=2*(cot(x)^2*cos(2*x)-y*csc(2*x)),y,x));
166 [y = (csc(2*x)+cot(2*x))*(log(sin(x)^2+cos(x)^2+2*cos(x)+1)
167 +log(sin(x)^2+cos(x)^2-2*cos(x)+1)+cos(2*x)+%c)];
168 [method,ode_check(eqn,ans[1])];
172 (pn_(23),ans:contrib_ode(eqn:'diff(y,x)=2*csc(2*x)*(sin(x)^3+y),y,x),ans:map(lambda([e],map(trigrat,e)),ans));
173 [y=-((sin(2*x)-2*%c*sin(x))/(2*cos(x)))];
174 [method,ode_check(eqn,ans[1])];
178 (pn_(24),ans:contrib_ode(eqn:'diff(y,x)=2*csc(2*x)*(1-tan(x)^2+y),y,x),ans:map(lambda([e],map(trigrat,e)),ans));
179 [y=(%c*sin(2*x)-2)/(cos(2*x)+1)];
180 [method,ode_check(eqn,ans[1])];
184 (pn_(25),ans:contrib_ode(eqn:'diff(y,x)=y*sec(x),y,x));
185 [y = %c*(tan(x)+sec(x))];
186 [method,ode_check(eqn,ans[1])];
190 (pn_(26),ans:contrib_ode(eqn:'diff(y,x)+tan(x)=(1-y)*sec(x),y,x));
191 [y=(x+%c)/(tan(x)+sec(x))];
192 [method,ode_check(eqn,ans[1])];
196 (pn_(27),ans:contrib_ode(eqn:'diff(y,x)=y*tan(x),y,x));
198 [method,ode_check(eqn,ans[1])];
202 (pn_(28),ans:contrib_ode(eqn:'diff(y,x)=cos(x)+y*tan(x),y,x));
203 [y=sec(x)*((sin(2*x)/2+x)/2+%c)];
204 [method,ode_check(eqn,ans[1])];
208 (pn_(29),ans:contrib_ode(eqn:'diff(y,x)=cos(x)-y*tan(x),y,x));
210 [method,ode_check(eqn,ans[1])];
214 (pn_(30),ans:contrib_ode(eqn:'diff(y,x)=sec(x)-y*tan(x),y,x));
215 [y=(tan(x)+%c)/sec(x)];
216 [method,ode_check(eqn,ans[1])];
220 (pn_(31),ans:contrib_ode(eqn:'diff(y,x)=sin(2*x)+y*tan(x),y,x));
221 [y=(%c-2*cos(x)^3/3)*sec(x)];
222 [method,ode_check(eqn,ans[1])];
226 (pn_(32),ans:contrib_ode(eqn:'diff(y,x)=sin(2*x)-y*tan(x),y,x));
227 [y=(%c-2*cos(x))/sec(x)];
228 [method,ode_check(eqn,ans[1])];
232 (pn_(33),ans:contrib_ode(eqn:'diff(y,x)=sin(x)+2*y*tan(x),y,x));
233 [y=(%c-cos(x)^3/3)*sec(x)^2];
234 [method,ode_check(eqn,ans[1])];
238 (pn_(34),ans:contrib_ode(eqn:'diff(y,x)=2*(1+sec(2*x)+y*tan(2*x)),y,x));
239 [y=sec(2*x)*(sin(2*x)+2*x+%c)];
240 [method,ode_check(eqn,ans[1])];
244 (pn_(35),ans:contrib_ode(eqn:'diff(y,x)=csc(x)+3*y*tan(x),y,x));
245 [y=sec(x)^3*(log(sin(x))-sin(x)^2/2+%c)];
246 [method,ode_check(eqn,ans[1])];
250 (pn_(36),ans:contrib_ode(eqn:'diff(y,x)=(a+cos(log(x))+sin(log(x)))*y,y,x));
251 [y=%c*%e^(x*(sin(log(x))+cos(log(x)))/2+x*(sin(log(x))-cos(log(x)))/2+a*x)];
252 (assume(x>0),ans:map(trigrat,ans[1]),forget(x>0),ans);
253 y=%c*%e^(x*sin(log(x))+a*x);
254 [method,ode_check(eqn,ans)];
258 (pn_(37),ans:contrib_ode(eqn:'diff(y,x)=6*exp(2*x)-y*tanh(x),y,x),0);
261 y=%e^(3*x)/cosh(x)+(3*%e^x)/cosh(x)+%c/cosh(x)$
262 [method,ode_check(eqn,ans[1])];
265 /* 38 - too general*/
266 /* 39 - too general */
271 (pn_(42),ans:contrib_ode(eqn:'diff(y,x)+1-x=(x+y)*y,y,x),0);
273 [method,ode_check(eqn,ans[1])];
277 (pn_(43),ans:contrib_ode(eqn:'diff(y,x)=(x+y)^2,y,x));
278 [[x=%c-atan(sqrt(%t)),y=-x-sqrt(%t)],[x=atan(sqrt(%t))+%c,y=sqrt(%t)-x]];
279 solve(ans[1][1],sqrt(%t));
280 [sqrt(%t)=-tan(x-%c)];
281 ans[1]:ev(ans[1][2],%[1]);
283 solve(ans[2][1],sqrt(%t));
284 [sqrt(%t)=tan(x-%c)];
285 ans[2]:ev(ans[2][2],%[1]);
287 [method,ode_check(eqn,ans[1]),ode_check(eqn,ans[2])];
291 (pn_(44),ans:contrib_ode(eqn:'diff(y,x)=(x-y)^2,y,x));
292 [[x = log(sqrt(%t)+1)/2-log(sqrt(%t)-1)/2+%c,y = x-sqrt(%t)],[x=-log(sqrt(%t)+1)/2+log(sqrt(%t)-1)/2+%c,y=x+sqrt(%t)]];
293 solve(ans[1][2],sqrt(%t));
296 x=log(-y+x+1)/2-log(-y+x-1)/2+%c;
298 2*x-2*%c = log(-y+x+1)-log(-y+x-1);
300 %e^(2*x-2*%c) = (-y+x+1)/(-y+x-1);
301 ans[1]:first(solve(%,y));
302 y=((x-1)*%e^(2*x-2*%c)-x-1)/(%e^(2*x-2*%c)-1);
303 solve(ans[2][2],sqrt(%t));
306 x=-log(y-x+1)/2+log(y-x-1)/2+%c;
308 2*x-2*%c = log(y-x-1)-log(y-x+1);
310 %e^(2*x-2*%c)=(y-x-1)/(y-x+1);
311 ans[2]:first(solve(%,y));
312 y=((x-1)*%e^(2*x-2*%c)-x-1)/(%e^(2*x-2*%c)-1);
313 [method,ode_check(eqn,ans[1]),ode_check(eqn,ans[2])];
317 (pn_(45),ans:contrib_ode(eqn:'diff(y,x)=3*(1-x+y)+(x-y)^2,y,x));
318 [y = (x*(%c*%e^x+1)-2*%c*%e^x-1)/(%c*%e^x+1) ];
319 [method,ode_check(eqn,ans[1])];
323 (pn_(46),ans:contrib_ode(eqn:'diff(y,x)=2*x-(1+x^2)*y+y^2,y,x));
324 [y = ((x^2+1)*'integrate(%e^(x^3/3+x),x)-%e^(x^3/3+x)+%c*x^2+%c)/('integrate(%e^(x^3/3+x),x)+%c)];
325 [method,ode_check(eqn,ans[1])];
329 (pn_(47),ans:contrib_ode(eqn:'diff(y,x)=x*(2+x^3)-(2*x^2-y)*y,y,x));
330 [y=(%c*x^3+x^2-%c)/(%c*x+1)];
331 [method,ode_check(eqn,ans[1])];
335 (pn_(48),ans:contrib_ode(eqn:'diff(y,x)=1+x*(2-x^3)+(2*x^2-y)*y,y,x));
336 [y = (x^2*(%c*%e^(2*x)+1)+%c*%e^(2*x)-1)/(%c*%e^(2*x)+1) ];
337 [method,ode_check(eqn,ans[1])];
341 (pn_(49),ans:contrib_ode(eqn:'diff(y,x)=cos(x)-(sin(x)-y)*y,y,x));
342 [y = (%e^cos(x)*sin(x)*'integrate(%e^-cos(x),x)+%c*%e^cos(x)*sin(x)-1)/(%e^cos(x)*'integrate(%e^-cos(x),x)+%c*%e^cos(x))];
343 [method,ode_check(eqn,ans[1])];
347 Fails as can't solve 'diff(z,x,2) - sin(2*x)*'diff(z,x) + cos(2*x)*z = 0
349 (pn_(50),ans:contrib_ode(eqn:'diff(y,x)=cos(2*x)+(sin(2*x)+y)*y,y,x));
350 [[y=-'diff(%u,x,1)/%u,-'diff(%u,x,1)*sin(2*x)+%u*cos(2*x)+'diff(%u,x,2) = 0]];
355 (pn_(52),ans:contrib_ode(eqn:'diff(y,x)=(3+x-4*y)^2,y,x));
356 [y = (x*(2*%c*%e^(4*x)+2)+5*%c*%e^(4*x)+7)/(8*%c*%e^(4*x)+8) ];
357 [method,ode_check(eqn,ans[1])];
361 (pn_(53),ans:contrib_ode(eqn:'diff(y,x)=(1+4*x+9*y)^2,y,x));
362 [y = -((x*(12*%c*%e^(12*%i*x)+12)+(2*%i*%c+3*%c)*%e^(12*%i*x)-2*%i+3)
363 /(27*%c*%e^(12*%i*x)+27))];
364 [method,ode_check(eqn,ans[1])];
369 /* 55 Riccati and separable*/
372 (pn_(55.1),ans:contrib_ode(eqn:'diff(y,x)=a+b*y^2,y,x));
373 [atan(sqrt(b)*y/sqrt(a))/(sqrt(a)*sqrt(b)) = x+%c];
375 [y = sqrt(a)*tan(sqrt(a)*sqrt(b)*x+%c*sqrt(a)*sqrt(b))/sqrt(b)];
376 [method,ode_check(eqn,%[1])];
383 (pn_(55.2),ans:contrib_ode(eqn:'diff(y,x)=a+b*y^2,y,x));
384 [log(-((sqrt(a)*sqrt(-b)-b*y)/(b*y+sqrt(a)*sqrt(-b))))/(2*sqrt(a)*sqrt(-b))=x+%c];
386 [y=-((sqrt(a)*sqrt(-b)*%e^(2*sqrt(a)*sqrt(-b)*x+2*%c*sqrt(a)*sqrt(-b))+sqrt(a)*sqrt(-b))/(b*%e^(2*sqrt(a)*sqrt(-b)*x+2*%c*sqrt(a)*sqrt(-b))-b))];
387 [method,ode_check(eqn,%[1])];
398 /* 62 Riccati - See Kamke 1.27 */
399 /* (pn_(62),ans:contrib_ode(eqn:'diff(y,x)=1+a*(x-y)*y,y,x)); */
404 (pn_(64),ans:contrib_ode(eqn:'diff(y,x)=x*y*(3+y),y,x));
405 [-((log(y+3)-log(y))/3)=x^2/2+%c];
407 y/(y+3) = %e^(3*(x^2/2+%c));
408 ans:first(solve(%,y));
409 y=-3*%e^(3*x^2/2+3*%c)/(%e^(3*x^2/2+3*%c)-1);
410 [method,ode_check(eqn,%)];
414 (pn_(65),ans:contrib_ode(eqn:'diff(y,x)=1-x-x^3+(1+2*x^2)*y-x*y^2,y,x));
415 [y = (x^2*%e^x+%e^x+x*(%c-%e^x))/(x*%e^x-%e^x+%c) ];
416 [method,ode_check(eqn,ans[1])];
420 (pn_(66),ans:contrib_ode(eqn:'diff(y,x)=x*(2+x^2*y-y^2),y,x));
421 [y = %e^-(x^4/4)*(x^2*%e^(x^4/4)*(sqrt(%pi)*%c*erf(x^2/2)+sqrt(%pi))
422 +2*%c)/(sqrt(%pi)*%c*erf(x^2/2)+sqrt(%pi))];
423 [method,ode_check(eqn,ans[1])];
427 (pn_(67),ans:contrib_ode(eqn:'diff(y,x)=x+(1-2*x)*y-(1-x)*y^2,y,x));
428 [y = (%e^x+%c*x+%c)/(%e^x+%c*x)];
429 [method,ode_check(eqn,ans[1])];
433 (pn_(68),ans:contrib_ode(eqn:'diff(y,x)=a*x*y^2,y,x));
435 ans:first(solve(ans[1],y));
437 [method,ode_check(eqn,ans)];
443 (pn_(72),ans:contrib_ode(eqn:'diff(y,x)=sin(x)*(2*sec(x)^2-y^2),y,x));
444 [[y='diff(%u,x,1)/(%u*sin(x)),2*%u*sec(x)^2*sin(x)^3-'diff(%u,x,2)*sin(x)+'diff(%u,x,1)*cos(x)=0]];
446 /* 73 Riccati - FIXME 2006-12-11 - Runs forever */
447 /* (pn_(73),ans:contrib_ode(eqn:'diff(y,x)+4*csc(x)=(3-cot(x))*y+sin(x)*y^2,y,x));
448 [[y=-'diff(%u,x,1)/(%u*sin(x)),-4*%u*csc(x)*sin(x)^2-'diff(%u,x,1)*((3-cot(x))*sin(x)+cos(x))+'diff(%u,x,2)*sin(x)=0]]; */
451 (pn_(74),ans:contrib_ode(eqn:'diff(y,x)=y*sec(x)+(sin(x)-1)^2,y,x));
452 [y = (tan(x)+sec(x))*(-8*(log(sin(x)^2/(cos(x)+1)^2+1)/4
453 -log(sin(x)/(cos(x)+1)+1)/2
455 *(2*sin(x)^2/(cos(x)+1)^2+2)))
456 +8*(-log(sin(x)^2/(cos(x)+1)^2+1)/8
457 +log(sin(x)/(cos(x)+1)+1)/4
458 -((sin(x)^3/(cos(x)+1)^3-sin(x)^2/(cos(x)+1)^2
460 /(4*sin(x)^4/(cos(x)+1)^4
461 +8*sin(x)^2/(cos(x)+1)^2+4)))
462 +2*(log(sin(x)/(cos(x)+1)+1)
463 -log(sin(x)^2/(cos(x)+1)^2+1)/2)+%c)];
464 /* y = (tan(x)+sec(x))/(%c+sin(x)) ??? */
465 [method,ode_check(eqn,ans[1])];
469 (pn_(75),ans:contrib_ode(eqn:'diff(y,x)+tan(x)*(1-y^2)=0,y,x));
470 [-((log(y+1)-log(y-1))/2) = log(sec(x))+%c];
472 (y-1)/(y+1)=%e^(2*(log(sec(x))+%c));
473 ans:first(solve(%,y));
474 y=-((%e^(2*%c)*sec(x)^2+1)/(%e^(2*%c)*sec(x)^2-1));
475 [method,ode_check(eqn,ans)];
481 (pn_(78),ans:contrib_ode(eqn:'diff(y,x)+(a*x+y)*y^2=0,y,x));
485 (pn_(79),ans:contrib_ode(eqn:'diff(y,x)+(a*exp(x)+y)*y^2=0,y,x));
489 (pn_(88),ans:contrib_ode(eqn:'diff(y,x)+2*x*y*(1+a*x^2*y^2)=0,y,x));
490 [y=%e^-x^2/sqrt(%c-a*(2*x^2+1)*%e^-(2*x^2)/2)];
491 [method,ode_check(eqn,ans[1])];
495 (pn_(91),ans:contrib_ode(eqn:'diff(y,x)+(tan(x)+y^2*sec(x))*y=0,y,x));
496 [y=1/(sec(x)*sqrt(2*sin(x)+%c))];
497 [method,ode_check(eqn,ans[1])];
501 (pn_(92),ans:contrib_ode(eqn:'diff(y,x)+y^3*sec(x)*tan(x)=0,y,x));
502 [1/(2*y^2)=1/cos(x)+%c];
503 ans:first(solve(ans[1],y));
504 y=-sqrt(cos(x)/(%c*cos(x)+1))/sqrt(2);
505 [method,ode_check(eqn,ans)];
508 /* 93 - Generic Abel equation */
511 (pn_(94),ans:contrib_ode(eqn:'diff(y,x)=(tan(x)+y^3*sec(x))*y,y,x));
512 [y=sec(x)/(%c-3*(tan(x)^3/3+tan(x)))^(1/3)];
513 [method,ode_check(eqn,ans[1])];
517 /* (pn_(95),ans:contrib_ode(eqn:'diff(y,x)=a*x^(n/(1-n))+b*y^n,y,x)); */
519 /* 96 - Too general */
520 /* 97 - Too general */
521 /* 98 - Too general */
524 (pn_(99),ans:contrib_ode(eqn:'diff(y,x)=sqrt(y),y,x));
526 [method,ode_check(eqn,ans[1])];
530 (pn_(100),ans:contrib_ode(eqn:'diff(y,x)=a+by+sqrt(c+d*y),y,x));
531 [((-2*by-2*a)*log(sqrt(d*y+c)+by+a)+2*sqrt(d*y+c))/d = x+%c];
532 [method,ode_check(eqn,ans[1])];