6 /* Bug #2796 ode2 with n declared constant
8 * Can't load ode2.mac if any formal function args are
11 (declare(n,constant), load(ode2), remove(n,constant));
14 /* Trivial ode - bug 866510 */
18 /* Examples from "The Maxima Book" */
20 ode2(x^2*'diff(y,x)+3*x*y=sin(x)/x, y, x);
23 y = -((cos(x)-cos(1)-1)/x^3);
27 soln:ode2('diff(y,x,2) + y = 4*x, y, x);
28 y = %k1*sin(x) + %k2*cos(x) + 4*x;
30 variationofparameters;
31 ic2(soln, x=0, y=1, 'diff(y,x)=3);
32 y = -sin(x)+cos(x)+4*x;
33 bc2(soln, x=0, y=3, x=2, y=1);
34 y = -((3*cos(2)+7)*sin(x)/sin(2)) + 3*cos(x) + 4*x;
36 ode2((3*x^2+4*x+2)=(2*y-1)*'diff(y,x), y, x);
37 y^2-y = x^3+2*x^2+2*x+%c;
41 ode2(x^2*cos(x*y)*'diff(y,x) + (sin(x*y)+x*y*(cos(x*y)))=0, y, x);
46 ode2( (2*x*y-exp(-2*y))*'diff(y,x)+y=0, y, x);
47 x*exp(2*y) - log(y) = %c;
53 ode2( 'diff(y,x)=(y/x)^2+2*(y/x), y, x);
58 ode2( 'diff(y,x)+(2/x)*y=(1/x^2)*y^3, y, x);
59 y = 1/(sqrt( 2/(5*x^5) + %c)*x^2);
65 ode2( 'diff(y,x,2)-3*'diff(y,x)+2*y=0, y, x);
66 y = %k1*exp(2*x) + %k2*exp(x);
70 ode2( 'diff(y,x,2)-4*'diff(y,x)+4*y=0, y, x);
71 y = (%k2*x + %k1)*exp(2*x);
75 ode2(x^2*'diff(y,x,2)+x*'diff(y,x)-y=0, y, x);
80 ode2( x^2*'diff(y,x,2)+4*x*'diff(y,x)+2*y=0, y, x);
85 ode2( x^2*'diff(y,x,2)+5*x*'diff(y,x)+4*y=0, y, x);
86 y=(%k2*log(x)+%k1)/x^2;
90 ode2( x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-1/4)*y=0, y, x);
91 y=(%k1*sin(x)+%k2*cos(x))/sqrt(x);
95 ode2( x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-4)*y=0, y, x);
96 y=%k1*bessel_j(2,x)+%k2*bessel_y(2,x);
100 ode2( (x-1)^2*'diff(y,x,2)+(x-1)*'diff(y,x)+((x-1)^2-4)*y=0, y, x);
101 y=%k1*bessel_j(2,x-1)+%k2*bessel_y(2,x-1);
105 ode2( x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-1/9)*y=0, y, x);
106 y=bessel_j(-1/3,x)*%k2+bessel_j(1/3,x)*%k1;
110 /* Bug report 2876387: asks if obvious non-integers are integers */
111 (declare(n,integer),ode2(x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-n^2)*y=0,y,x));
112 y = %k2*bessel_y(n,x)+%k1*bessel_j(n,x);
113 (remove(n,integer),method);
116 (declare(v,noninteger),ode2(x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-v^2)*y=0,y,x));
117 y = %k1*bessel_j(v,x)+%k2*bessel_j(-v,x);
118 (remove(v,noninteger),method);
121 ode2(x^2*'diff(y,x,2)+x*'diff(y,x)+(x^2-3)*y=0,y,x);
122 y = %k1*bessel_j(sqrt(3),x)+%k2*bessel_j(-sqrt(3),x);
126 ode2( 'diff(y,x,2)+2*'diff(y,x)+y=exp(x), y, x);
127 y=exp(x)/4+(%k2*x+%k1)*exp(-x);
129 variationofparameters;
133 ode2( x*'diff(y,x,2)+('diff(y,x))^2=0, y, x);
134 /* y='integrate(1/(log(x)+%k1),x)+%k2;
135 Because of adding more integrals for the power function we get a result
137 y=%k2-expintegral_e(1,-log(x)-%k1)*%e^-%k1;
141 ode2( y*'diff(y,x,2)+('diff(y,x))^2=0, y, x);
146 eq: 'diff(y,x,2)+x*'diff(y,x)+exp(-x^2)*y=0;
147 'diff(y,x,2)+x*'diff(y,x,1)+%e^-x^2*y = 0;
149 y = %k1*sin((1/2) * sqrt(2)*sqrt(%pi)*erf(x/sqrt(2)))+%k2*cos((1/2) * sqrt(2)*sqrt(%pi)*erf(x/sqrt(2)));
150 is(ratsimp(ev(eq,ans,diff)));
155 eq:x*'diff(y,x,2)+(x^2-1)*'diff(y,x,1)+x^3*y=0;
156 x*'diff(y,x,2)+(x^2-1)*'diff(y,x,1)+x^3*y=0;
158 y=%e^-(x^2/4)*(%k1*sin(sqrt(3)*x^2/4)+%k2*cos(sqrt(3)*x^2/4));
159 is(ratsimp(ev(eq,ans,diff)));
164 /* Tests of desolve */
166 eqn1:'diff(f(x),x) = sin(x)+'diff(g(x),x);
167 'diff(f(x),x,1) = 'diff(g(x),x,1)+sin(x);
168 eqn2:'diff(g(x),x,2) = 'diff(f(x),x)-cos(x);
169 'diff(g(x),x,2) = 'diff(f(x),x,1)-cos(x);
170 desolve([eqn1,eqn2],[f(x),g(x)]);
171 [f(x)=%e^x*(at('diff(g(x),x,1),x = 0))-at('diff(g(x),x,1),x = 0)+f(0),g(x)=%e^x*(at('diff(g(x),x,1),x=0))-at('diff(g(x),x,1),x = 0)+cos(x)+g(0)-1];
172 atvalue('diff(g(x),x),x = 0,a);
174 atvalue(f(x),x = 0,1);
176 desolve([eqn1,eqn2],[f(x),g(x)]);
177 [f(x) = a*%e^x-a+1,g(x) = cos(x)+a*%e^x-a+g(0)-1];
178 remove(f,atvalue,g,atvalue);
181 atvalue('diff(g(x),x),x = 0,a);
183 atvalue(f(x),x = 0,1);
185 desolve([eqn1,eqn2],[f(x),g(x)]);
186 [f(x) = a*%e^x-a+1,g(x) = cos(x)+a*%e^x-a+g(0)-1];
188 eqn3: 'diff(f(x),x,2)+f(x)=2*x;
189 'diff(f(x),x,2)+f(x)=2*x;
191 ''(f(x) = sin(x)*(at('diff(f(x),x,1),x = 0)-2)+f(0)*cos(x)+2*x);
194 errcatch(desolve('diff(f(x),x),x));
197 /* Examples mentioned in bug report [ 1063454 ] bug in ode2
198 * First one was reported to fail in CMUCL with "run out of heap" message.
199 * Others were reported to be OK. Put them all here for good measure.
202 (ode2 ('diff(y, t, 2) + 'diff(y, t) + y - sin(t), y, t),
203 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + %% - sin(t)));
206 (ode2 ('diff(y, t, 2) + 'diff(y, t) + 2*y - sin(t), y, t),
207 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + 2*%% - sin(t)));
210 (ode2 ('diff(y, t, 2) + 'diff(y, t) + y - exp(%i*t), y, t),
211 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + %% - exp(%i*t)));
214 /* bug report 1063454 claims "maxima gets stuck" on the following */
215 (integrate (my_integrand : exp(t/2) * sin(t) * sin(sqrt(3) * t/2), t),
216 ratsimp (exponentialize (diff (%%, t) - my_integrand)));
219 /* Examples to show that ic2 works as expected after revision 1.5 of ode.mac
222 'diff(y,x,2)+y*('diff(y,x,1))^3 = 0;
223 'diff(y,x,2)+y*('diff(y,x,1))^3 = 0;
226 (y^3+6*%k1*y)/6 = x+%k2;
228 ratsimp(ic2(soln, x=0, y=0, 'diff(y,x,1)=2));
231 ratsimp(ic2(soln, x=0, y=0, 'diff(y,x,1)=1));
234 /* This is the example of the bug report
235 * ID:2881021 - ic2 and bc2 may return incorrect results (solution suggeste)
238 ratsimp(ic2(soln, x=0, y=1, 'diff(y,x,1)=2));
241 /* These examples show that ic2 works for a list of equation and nested
245 ratsimp(ic2([soln, soln, soln], x=0, y=0, 'diff(y,x,1)=2));
246 [(y^3+3*y)/6=x, (y^3+3*y)/6=x, (y^3+3*y)/6=x];
248 ratsimp(ic2([soln, [soln, soln]], x=0, y=0, 'diff(y,x,1)=2));
249 [(y^3+3*y)/6=x, [(y^3+3*y)/6=x, (y^3+3*y)/6=x]];
251 /* Bug report ID: 1839088 - ic2 fails with division by 0
252 * Maxima no longer gives an error, but does not find the solution.
255 ode2(y*'diff(y,x,2)=a, y, x);
256 [sqrt(%pi)*%i*%e^-%k1*erf(%i*sqrt(a*log(y)+%k1*a)/sqrt(a))/(sqrt(2)*sqrt(a))
258 -sqrt(%pi)*%i*%e^-%k1*erf(%i*sqrt(a*log(y)+%k1*a)/sqrt(a))/(sqrt(2)*sqrt(a))
261 ic2(%,x=0,y=b,diff(y,x)=0);
264 /* Bug report ID: 2997443 - ic2 fails
265 * Maxima no longer gives an error, but does not find the solution.
266 * The solution of ic2 could be: y=1/20*(sqrt(160*x+1)-1)
269 ode2('diff(x,t,2)+5*'diff(x,t)^3, x, t);
270 [x = %k2-2*1/sqrt(1/(t+%k1))/sqrt(10),x = 2*1/sqrt(1/(t+%k1))/sqrt(10)+%k2];
272 ic2(%,t=0,x=0,'diff(x,t)=4);
275 /* Bug report ID: 1789213 - ic1 for solution containing indefinite integral
276 * More general implementation of ic1, which handles a noun form of an
277 * integral correctly. The result simplifies correctly, if we define
278 * a function and reevaluate the result.
280 sol: ode2(kappa(p) = -'diff(V, p) / V, V, p);
281 V = %c*%e^-'integrate(kappa(p),p);
283 ic1(sol, p = p0, V = V0);
284 V = V0*%e^('at('integrate(kappa(p),p),[p = p0,V = V0])
285 -'integrate(kappa(p),p));
287 (kappa(x):=x, ev(%,nouns));
288 V = %e^(p0^2/2-p^2/2)*V0;
290 /* Bug report ID: 1621 Wrong solution to ode2
292 * 'diff(y,t,2)-a*'diff(y,t)=-t with a=0
294 * Test case is a 2nd order non-homogeneous linear ode with constant
295 * coefficients. When solving homogeneous ode, cc2 asked if a=0, then
296 * returned a solution involving a.
301 ode2('diff(y,t,2)-a*'diff(y,t)=0,y,t);
304 ode2('diff(y,t,2)-a*'diff(y,t)=-t,y,t);
305 y=(-t^3/6)+%k2*t+%k1;
311 /* Feature request #192 Modified Bessel's differential equation DLMF 10.25.1
313 * x^2*'diff(y,x,2)+x*'diff(y,x)-(x^2+n^2)*y = 0
317 mbde:x^2*'diff(y,x,2)+x*'diff(y,x)+(-x^2-n^2)*y = 0;
318 x^2*'diff(y,x,2)+x*'diff(y,x)+(-x^2-n^2)*y = 0;
320 s:ode2(eq:subst(n=1,mbde),y,x);
321 y = bessel_k(1,x)*%k2+bessel_i(1,x)*%k1;
325 s:ode2(eq:subst(n=2,mbde),y,x);
326 y = bessel_k(2,x)*%k2+bessel_i(2,x)*%k1;
330 s:ode2(eq:subst(n=1/2,mbde),y,x);
331 y = (%k1*sinh(x)+%k2*%e^-x)/sqrt(x);
335 s:ode2(eq:subst(n=3/2,mbde),y,x);
336 y = bessel_i(-(3/2),x)*%k2+bessel_i(3/2,x)*%k1;
343 y = %k2*bessel_k(n,x)+%k1*bessel_i(n,x);
347 (kill(all),remove(n,integer));