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);
193 /* Examples mentioned in bug report [ 1063454 ] bug in ode2
194 * First one was reported to fail in CMUCL with "run out of heap" message.
195 * Others were reported to be OK. Put them all here for good measure.
198 (ode2 ('diff(y, t, 2) + 'diff(y, t) + y - sin(t), y, t),
199 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + %% - sin(t)));
202 (ode2 ('diff(y, t, 2) + 'diff(y, t) + 2*y - sin(t), y, t),
203 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + 2*%% - sin(t)));
206 (ode2 ('diff(y, t, 2) + 'diff(y, t) + y - exp(%i*t), y, t),
207 rhs(%%), ratsimp (diff(%%, t, 2) + diff(%%, t) + %% - exp(%i*t)));
210 /* bug report 1063454 claims "maxima gets stuck" on the following */
211 (integrate (my_integrand : exp(t/2) * sin(t) * sin(sqrt(3) * t/2), t),
212 ratsimp (exponentialize (diff (%%, t) - my_integrand)));
215 /* Examples to show that ic2 works as expected after revision 1.5 of ode.mac
218 'diff(y,x,2)+y*('diff(y,x,1))^3 = 0;
219 'diff(y,x,2)+y*('diff(y,x,1))^3 = 0;
222 (y^3+6*%k1*y)/6 = x+%k2;
224 ratsimp(ic2(soln, x=0, y=0, 'diff(y,x,1)=2));
227 ratsimp(ic2(soln, x=0, y=0, 'diff(y,x,1)=1));
230 /* This is the example of the bug report
231 * ID:2881021 - ic2 and bc2 may return incorrect results (solution suggeste)
234 ratsimp(ic2(soln, x=0, y=1, 'diff(y,x,1)=2));
237 /* These examples show that ic2 works for a list of equation and nested
241 ratsimp(ic2([soln, soln, soln], x=0, y=0, 'diff(y,x,1)=2));
242 [(y^3+3*y)/6=x, (y^3+3*y)/6=x, (y^3+3*y)/6=x];
244 ratsimp(ic2([soln, [soln, soln]], x=0, y=0, 'diff(y,x,1)=2));
245 [(y^3+3*y)/6=x, [(y^3+3*y)/6=x, (y^3+3*y)/6=x]];
247 /* Bug report ID: 1839088 - ic2 fails with division by 0
248 * Maxima no longer gives an error, but does not find the solution.
251 ode2(y*'diff(y,x,2)=a, y, x);
252 [sqrt(%pi)*%i*%e^-%k1*erf(%i*sqrt(a*log(y)+%k1*a)/sqrt(a))/(sqrt(2)*sqrt(a))
254 -sqrt(%pi)*%i*%e^-%k1*erf(%i*sqrt(a*log(y)+%k1*a)/sqrt(a))/(sqrt(2)*sqrt(a))
257 ic2(%,x=0,y=b,diff(y,x)=0);
260 /* Bug report ID: 2997443 - ic2 fails
261 * Maxima no longer gives an error, but does not find the solution.
262 * The solution of ic2 could be: y=1/20*(sqrt(160*x+1)-1)
265 ode2('diff(x,t,2)+5*'diff(x,t)^3, x, t);
266 [x = %k2-2*1/sqrt(1/(t+%k1))/sqrt(10),x = 2*1/sqrt(1/(t+%k1))/sqrt(10)+%k2];
268 ic2(%,t=0,x=0,'diff(x,t)=4);
271 /* Bug report ID: 1789213 - ic1 for solution containing indefinite integral
272 * More general implementation of ic1, which handles a noun form of an
273 * integral correctly. The result simplifies correctly, if we define
274 * a function and reevaluate the result.
276 sol: ode2(kappa(p) = -'diff(V, p) / V, V, p);
277 V = %c*%e^-'integrate(kappa(p),p);
279 ic1(sol, p = p0, V = V0);
280 V = V0*%e^('at('integrate(kappa(p),p),[p = p0,V = V0])
281 -'integrate(kappa(p),p));
283 (kappa(x):=x, ev(%,nouns));
284 V = %e^(p0^2/2-p^2/2)*V0;
286 /* Bug report ID: 1621 Wrong solution to ode2
288 * 'diff(y,t,2)-a*'diff(y,t)=-t with a=0
290 * Test case is a 2nd order non-homogeneous linear ode with constant
291 * coefficients. When solving homogeneous ode, cc2 asked if a=0, then
292 * returned a solution involving a.
297 ode2('diff(y,t,2)-a*'diff(y,t)=0,y,t);
300 ode2('diff(y,t,2)-a*'diff(y,t)=-t,y,t);
301 y=(-t^3/6)+%k2*t+%k1;