# differential equation solver; # solve differential equation and fractional differential equation for unknown y with independent variable x; # dsolve(eq,y) # there are 3 way to input derivative y: y', y(1,x), or ds(y,x,1) # there are 3 way to input second order derivative y: y'', y(2,x), or ds(y,x,2) # e.g. dsolve( y' = x*y, y) # dsolve( y(0.5,x)=y^2 ) # dsolve(a_,y_,x_,q_) = If(isfree(a,y),d(a,x,-q), If(isfree(a/y,y),mittag(q,d(a/y,x,-q)), If(isfree(a,x), solve(d(1/a, y,-q)=x^q/q!,y) ))); # dsolve(a_+b_, y_,x_,q_) := If(isfree(a,b,y), d(a+b,x,-q)+C_1+if(q>1, C_2*x,0), If(isfree(a,b,x), solve(d(1/(a+b),y,-q)=x^q/q!,y)+if(q>1, C_2*x^2+C_1*x,C_1+x), If(isfree(a,y) and isfree(d(b,y),y), block(dsolve:=d(d(b,y),x,-q),simplify(mittag(q,dsolve)*d(a*mittag(q,-dsolve),x,-q))+mittag(q,dsolve)), If(isfree(b,y) and isfree(d(a,y),y), block(dsolve:=d(d(a,y),x,-q),simplify(mittag(q,dsolve)*d(b*mittag(q,-dsolve),x,-q))+mittag(q,dsolve)) )))); #dsolve(a_+y_,c_,x_,y_,1):=if(isconstant(a), block(xx:=dsolve(expand(replace(c,y,x(1,t))),x,t,2), (x=xx, y=d(xx,t)-a))); #dsolve(a_*y_,c_,x_,y_,1):=if(isconstant(a), block(xx:=dsolve(expand(a*replace(c,y,x(1,t)/a)),x,t,2), (x=xx, y=d(xx,t)/a))); #dsolve(a_*y_+b_,c_,x_,y_,1):=if(hasnot(a,b,x), block(xx:=dsolve(expand(a*replace(c,y,x(1,t)/a)),x,t,2), (x=xx, y=d(xx,t)/a-b))); #dsolve(a_,c_*x_,x_,y_,1):=if(isconstant(c), block(yy:=dsolve(expand(c*replace(a,x,y(1,t)/c)),y,t,2), (y=yy, x=d(yy,t)/c))); dsolve(a_+y_, y_,x_,q_) := If(isfree(a,y), gsolution(1,y,x,q)+If(isfree(a,x),-a,psolution(1,a,y,x,q))); #dsolve(a_+y_, y_,x_,q_) := If(isfree(a,y), If(isfree(a,x), If(isinteger(q), C_1*exp(x)-a, C_1*mittag(q,x^q)-a ), C_1*exp(x)+psolution(1,a,y,x,q) )); #dsolve(y_+z_, y_,x_,q_) := If(isfree(z,y), If(isfree(z,x), If(isinteger(q), C_1*exp(x)-z, C_1*mittag(q,x^q)-z ), C_1*exp(x)+psolution(1,z,y,x,q) )); #dsolve(a_+b_*y, y_,x_,q_) := If(isfree(a,b,y), if(isfree(a,x), If(b>0, C_1*exp(b^(1/q)*x)-a/b,C_1*mittag(q,b^sgn(q)*x^abs(q)/(abs(q))!))-a/b, If(b>0, C_1*exp(b^(1/q)*x)+psolution(b,a,y,x,q) ,C_1*mittag(abs(q),d(b,x,-q)) +psolution(b,a,y,x,q) ))); #dsolve(b_*y_+z_, y_,x_,q_) := If(isfree(z,b,y), If(isinteger(q), C_1*exp(b^(1/q)*x), gsolution(b,y,x,q) )+psolution(b,z,y,x,q) ); dsolve(a_+b_*y_, y_,x_,q_) := gsolution(b,y,x,q)+psolution(b,a,y,x,q); dsolve(a_*y_+b_*y_, y_,x_,q_) := If(isfree(a,b,y), C_1*mittag(q,d(a+b,x,-q)*q!) ); dsolve(a_*y_+y_, y_,x_,q_) := If(isfree(a,y), C_1*mittag(q,d(a+1,x,-q)*q!) ); #dsolve(a_+a_*y_, y_,x_,q_) := If(isfree(a,y), If(isfree(a,x), If(q>0, C_1*exp(a^(1/q)*x)-1, C_1*mittag(-q,1/a*x^(-q)/(-q)!) ), If(q>0,C_1*mittag(q,d(a,x,-q))-1, C_1*mittag(-q,d(a,x,-q))*d(a,x,-q) ) )); #dsolve(x_^q_+y_, y_,x_,q_) := -x^q-q!; #dsolve(x_^n_+b_*y_, y_,x_,q_) := If(isfree(b,x) and isfree(b,y), If(n==q, -x^q/b-q!/b^2, If(q>0, n!*x^(n+q)*mittag(q,1+n+q,b*x^q), gamma(n+1)*x^n*mittag(-q,n+1,1/b*x^(-q)) ))); #dsolve(x_^n_+b_*y_, y_,x_,q_) := If(isfree(b,x) and isfree(b,y), If(n==q, -x^n/b-q!/b^2, n!*x^(n+q)*mittag(q,1+n+q,b*x^q) )); #dsolve(a_*x_^n_+b_*y_, y_,x_,q_) := If(isfree(a,b,x) and isfree(a,b,y), If(n==q, -a*x^n/b-a*q!/b^2, a*n!*x^(n+q)*mittag(q,1+n+q,b*x^q) )); #dsolve(x_^n_+y, y_,x_,q_) := If(n==q, -x^n-n!, n!*x^(n+q)*mittag(q,1+n+q,x^q)); #dsolve(a_*x_^n_+y, y_,x_,q_) := If(isfree(a,x) and isfree(a,y), If(n==q, -a*x^n-a*n!, a*n!*x^(n+q)*mittag(q,1+n+q,x^q) )); #dsolve(x_^n_+y+c_, y_,x_,q_) := If(isfree(c,x) and isfree(c,y), If(n==q, -x^n-n!-c, n!*x^(n+q)*mittag(q,1+n+q,x^q)-c)); #dsolve(a_*x_^n_+y+c_, y_,x_,q_) := If(isfree(a,c,x) and isfree(a,c,y), If(n==q, -a*x^n-a*n!-c, a*n!*x^(n+q)*mittag(q,1+n+q,x^q)-c )); #dsolve(x_^n_+b_*y_+c_, y_,x_,q_) := If(isfree(b,c,x) and isfree(b,c,y), If(n==q, -x^n/b-q!/b^2-c/b, n!*x^(n+q)*mittag(q,1+n+q,b*x^q)-c/b )); #dsolve(a_*x_^n_+b_*y_+c_, y_,x_,q_) := If(isfree(a,b,c,x) and isfree(a,b,c,y), If(n==q, -a*x^n/b-a*q!/b^2-c/b, a*n!*x^(n+q)*mittag(q,1+n+q,b*x^q)-c/b )); #dsolve(a_*x_+b_*y_, y_,x_,q_) := If(isfree(a,b,x) and isfree(a,b,y), a*x^(1+q)*mittag(q,2+q,b*x^q)); #dsolve(a_*x_+y_, y_,x_,q_) := If(isfree(a,x) and isfree(a,y), a*x^(1+q)*mittag(q,2+q,x^q)); #dsolve(x_+b_*y_, y_,x_,q_) := If(isfree(b,x) and isfree(b,y), x^(1+q)*mittag(q,2+q,b*x^q) ); #dsolve(x_+y, y_,x_,q_) := x^(1+q)*mittag(q,2+q,x^q); #dsolve(a_*x_+y_+c_, y_,x_,q_) := If(isfree(a,c,x) and isfree(a,c,y), If(q>0,a*x^(1+q)*mittag(q,2+q,x^q)-c,a*x^(1+q)*mittag(q,2+q,x^q) )); #dsolve(x_+b_*y_+c_, y_,x_,q_) := If(isfree(b,c,x) and isfree(c,b,y), If(q>0,x^(1+q)*mittag(q,2+q,b*x^q)-c/b,x^(1+q)*mittag(q,2+q,b*x^q) )); #dsolve(x_+y_+c_, y_,x_,q_) := If(isfree(c,x) and isfree(c,y), If(q>0,x^(1+q)*mittag(q,2+q,x^q)-c,x^(1+q)*mittag(q,2+q,x^q) )); #dsolve(a_*x_+b_*y_+c_, y_,x_,q_) := If(isfree(a,b,c,x) and isfree(a,b,c,y), If(q>0, a*x^(1+q)*mittag(q,2+q,b*x^q)-c/b,a*x^(1+q)*mittag(q,2+q,b*x^q) )); #dsolve(a_*x_+x_*y_, y_,x_,q_) := If(isfree(a,x) and isfree(a,y), C_1*mittag(q,x^(1+q)/(1+q)!)-a); #dsolve(x_+b_*x_*y_, y_,x_,q_) := if(isfree(b,x) and isfree(a,y), C_1*mittag(abs(q),b*x^(1+abs(q))/(1+abs(q))!)-1/b); dsolve(a_*x_+b_*x_*y(p_,x_), y_,x_,q_) := If(isfree(a,b,x) and isfree(a,b,y), C_1*d(mittag(q-p,b*x^(1+q-p)/(1+q-p)!)-a/b,x,-p)); #dsolve(b_*y^n_, y_,x_,q_) := If(isfree(b,y), If(isfree(b,x), b^(1-n)*fallingfactorial(q/(1-n),q)^(1/(n-1))*(x+C_1)^(q/(1-n)), (1/fallingfactorial(-n,q)*d(b,x,-q))^(1/(q-n)) )); dsolve(y_^n_, y_,x_,q_) := fallingfactorial(-n,-q)^(1/(-q+n))*(x+C_1)^(1/(q-n)) ; #dsolve(b_*y_, y_,x_,q_) := if(isfree(b,y), If(b>0, C_1*exp(b^(1/q)*x)+if(iseven(q), C_2*exp(-b^(1/q)*x),0), If(b<0, C_1*mittag(q,b*x^q), C_1*mittag(q,d(b,x,-q)*q!) ))); dsolve(b_*y_, y_,x_,n_) := gsolution(b,y,x,n); #dsolve(b_*x_*y_, y_,x_,q_) := If(isfree(b,y), C_1*mittag(q,b*x^(q+1)/(1+q)), C_1*mittag(q,d(b*x,x,-q)*q!) ); #dsolve(x_*y_, y_,x_,q_) := C_1*mittag(q,x^(1+q)/(1+q)); dsolve(y_, y_,x_,q_) := if(q==3, C_1*exp(x)+C_2*cos(x)+C_3*sin(x), if(iseven(q),C_1*exp(-x)+C_2*exp(x),C_1*E(q,x^q) )); dsolve(e^x_, y_,x_,q_) := exp(x)+if(q>0, sum(c(k+1)*x^k,k,0,ceil(q)-1,1),0 ); dsolve(0, y_,x_,q_) := if(q>0, sum(c(k+1)*x^k,k,0,ceil(q)-1,1) ); #dsolve(f_, y_,x_,1) :=dsolve(f, y,x); dsolve(a_ and b_, y_,x_,p_) := dsolve(a, y,x,p) and dsolve(b, y,x,p); dsolve(a_, y_,x_,-1) := if(isfree(a,y),d(a,x), dsolve(d(replace(a,y,y(x)),x)-y)); dsolve(a_+b_*y_, y_,x_,-1) := if(isfree(a,b,y), if(isfree(b,x), C_1*exp(integrate((1-d(b,x))/b,x)), C_1*exp(integrate((1-d(b,x))/b,x))+psolution((1-d(b,x))/b,-d(a,x)/b,y,x,1) )); dsolve(y(1,x_),y_,x_,3):=C_1+C_2*e^(x)+C_3*e^(-x); dsolve(y(2,x_),y_,x_,3):=C_1+C_2*e^(x)+C_3*x; dsolve(b_*y(1,x_),y_,x_,3):=gsolution(0,b,y,x,2)+C_3; dsolve(b_*y(2,x_),y_,x_,3):=C_1+C_2*e^(int(b,x))+C_3*x; dsolve(a_+b_*y_, y_,x_,2) := if(isfree(a,b,y), if(a==b, gsolution(0,b,y,x,2)-1, gsolution(0,b,y,x,2)+psolution(b,a,y,x,2) )); dsolve(z_+b_*y_, y_,x_,2) := if(isfree(z,b,y), if(z==b, gsolution(0,b,y,x,2)-1, gsolution(0,b,y,x,2)+psolution(b,z,y,x,2) )); #dsolve(a_+y_, y_,x_,2) := if(isfree(a,y),if(isfree(a,x), C_1*exp(x)+C_2*exp(-x)-a, C_1*exp(x)+C_2*exp(-x)-1/2*exp(-x)*int(exp(x)*a,x)+1/2*exp(x)*int(exp(-x)*a,x) )); dsolve(a_+y_, y_,x_,2) := if(isfree(a,y),if(isfree(a,x), C_1*exp(x)+C_2*exp(-x)-a, C_1*exp(x)+C_2*exp(-x)+psolution(1,a,y,x,2) )); dsolve(x_+y_, y_,x_,2) := C_1*exp(x)+C_2*exp(-x)-x; dsolve(x_+b_*y_, y_,x_,2) := if(isfree(b,x), gsolution(0,b,y,x,2)-x/b, gsolution(0,b,y,x,2)+psolution(b,x,y,x,2) ); dsolve(a_*x_+b_*y_, y_,x_,2) := if(isfree(a,b,x), gsolution(0,b,y,x,2)-a*x/b, gsolution(0,b,y,x,2)+psolution(b,a*x,y,x,2) ); dsolve(a_*x_+b_*y_+c_, y_,x_,2) := if(isfree(a,b,c,x), gsolution(0,b,y,x,2)-a*x/b-c/b, gsolution(0,b,y,x,2)-a*x/b+psolution(b,c,y,x,2) ); dsolve(b_*y_, y_,x_,2) := if(isfree(b,y), gsolution(0,b,y,x,2) ); dsolve(x_*y_, y_,x_,2) := C_1*AiryAi(x)+C_2*AiryBi(x); #dsolve(a_*x_*y_, y_,x_,2) := if(isfree(a,x) and isfree(a,y), C_1*AiryAi(cbrt(a)*x)+C_2*AiryBi(cbrt(a)*x)); dsolve(a_*x_*y_, y_,x_,2) := if(isfree(a,x) and isfree(a,y), gsolution(a*x,y,x,2) ); dsolve(c_/x_^2*y_, y_,x_,2) := if(isfree(c,x), gsolution(0,c/x^2,y,x,2) ); dsolve(y_, y_,x_,-1) :=e^x; dsolve(y_, y_,x_,2) := C_1*exp(x)+C_2*exp(-x); dsolve(y_, y_,x_,3) := C_1*exp(x)+C_2*exp(-x/2)*sin(sqrt(3)/2x)+C_3*exp(-x/2)*cos(sqrt(3)/2x); dsolve(y_, y_,x_,4) := C_1*exp(x)+C_2*exp(-x)+C_3*cos(x)+C_4*sin(x); #dsolve(a_+b_, y_,x_) := If(isfree(a,b,y), integrate(a+b,x)+C_1, If(has(a,y) and has(b,y) and isfree(d(a+b,y),y), exp(integrate(d(a+b,y),x))*C_1, If(isfree(b,y) and isfree(d(a,y),y), block(dsolve:=int(d(a,y),x),exp(dsolve)*int(b*exp(-dsolve),x)+exp(dsolve)*C_1), If(isfree(a,y) and isfree(d(b,y),y), block(dsolve:=int(d(b,y),x),exp(dsolve)*int(a*exp(-dsolve),x)+exp(dsolve)*C_1) )))); #dsolve(a_+b_*y_,y_,x_):=If(isfree(a,b,y), If(isfree(a,b,x), C_1*exp(b*x)-a/b, block(dsolve:=integrate(b,x), expand(exp(dsolve)*integrate(a*exp(-dsolve),x))+exp(dsolve)*C_1 ) )); dsolve(a_+y_*z_,y_,x_,1):=If(isfree(a,z,y), If(isfree(a,z,x), C_1*exp(z*x)-a/z, C_1*exp(integrate(z,x))+psolution(z,a,y,x,1) )); #dsolve(b_*y_+z_,b_,x_,1):=If(isfree(z,y,b), If(isfree(z,y,x), C_1*exp(y*x)-z/y, C_1*exp(integrate(y,x))+psolution(y,z,b,x,1) )); #dsolve(b_*y_+z_,y_,x_,1):=If(isfree(z,b,y), If(isfree(z,b,x), C_1*exp(b*x)-z/b, C_1*exp(integrate(b,x))+psolution(b,z,y,x,1) )); dsolve(a_+b_*y_,y_,x_,1):=If(isfree(a,b,y), If(isfree(a,b,x), C_1*exp(b*x)-a/b, C_1*exp(integrate(b,x))+psolution(b,a,y,x,1) )); dsolve(a_+a_*y_,y_,x_,1):=If(isfree(a,y), C_1*exp(integrate(a,x))-1); #dsolve(a_+y_,y_,x_,1):=If(isfree(a,y), If(isfree(a,x), C_1*exp(x)-a, expand(exp(x)*integrate(a*exp(-x),x))+exp(x)*C_1 )); #dsolve(y_+z_,y_,x_,1):=If(isfree(z,y), If(isfree(z,x), C_1*exp(x)-z, expand(exp(x)*integrate(z*exp(-x),x))+exp(x)*C_1 )); #dsolve(a_+y_+z_,y_,x_,1):=If(isfree(a,z,y), If(isfree(a,z,x), C_1*exp(x)-a-z, expand(exp(x)*integrate((a+z)*exp(-x),x))+exp(x)*C_1 )); #dsolve(a_+b_*y_+z_,y_,x_,1):=If(isfree(a,b,z,y), If(isfree(a,b,z,x), C_1*exp(b*x)-a/b-z/b, expand(exp(b*x)*integrate((a+z)*exp(-b*x),x))+exp(b*x)*C_1 )); dsolve(a_*y_+y_,y_,x_,q):=If(isfree(a,y), C_1*mittag(q,d(a+1,y,-q)*q!) ); dsolve(a_*y_+b_*y_,y_,x_,q_):=If(isfree(a,b,y), C_1*mittag(q,d(a+b,x,-q)*q!) ); dsolve(x_+x_*y_, x_,y_,q_) := C_1*mittag(q,d(1+y,y,-q)*q!); dsolve(x_+b_*x_*y_, x_,y_,q_) := If(isfree(b,x), C_1*mittag(q,d(1+b*y,y,-q)*q!) ); dsolve(a_*x_+b_*x_*y_, x_,y_,q_) := If(isfree(a,b,x), C_1*mittag(q,d(a+b*y,y,-q)*q!) ); dsolve(y(p_,x_),y_,x_,q_):= C_1*e^x+if(p>0,C_2,0); #dsolve(b_*y(p_,x_),y_,x_,q_):=if(isfree(b,y), if(b>0, C_1*exp(b^(1/(q-p))*x)+if(p>0,C_2,0), C_1*d(mittag(q-p,d(b,x,p-q)),x,-p)+if(p>0,C_2,0) )); #dsolve(y(p_,x_)+c_,y_,x_,q_):= d(dsolve(c+y,y,x,q-p),x,-p); #dsolve(b_*y(p_,x_)+c_,y_,x_,q_):=if(isfree(b,y), d(dsolve(c+b*y,y,x,q-p),x,-p)); dsolve(b_*y(p_,x_),y_,x_,q_):= C_1*exp(b^(1/(q-p))*x)+if(p>0,C_2,0); dsolve(y(p_,x_)+c_,y_,x_,q_):= C_1*exp(x)+if(p>0,C_2,0)+psolution(1,p,0,c,y,x,q); dsolve(b_*y(p_,x_)+c_,y_,x_,q_):= C_1*exp(b^(1/(q-p))*x)+if(p>0,C_2,0)+psolution(b,p,0,c,y,x,q); #dsolve(y(p_,x_)+xy_, xy_,x_,q_) := if(q==2p, C_1*e^(((1+sqrt(5))/2)^(1/p)*x)+C_2*e^(((1-sqrt(5))/2)^(1/p)*x), C_1*exp(nsolve(x^q-x^p-1,x)*x) ); #dsolve(y(p_,x_)+c_*xy_, xy_,x_,q_) := if(isfree(c,y) and isfree(c,x), if(q==2p, if(c== -0.25, C_1*exp(2^(-1/p)*x)*x+C_2*exp(2^(-1/p)*x), C_1*e^(((1+sqrt(1+4c))/2)^(1/p)*x)+C_2*e^(((1-sqrt(1+4c))/2)^(1/p)*x)), C_1*exp(nsolve(x^q-x^p-c,x)*x) )); #dsolve(b_*y(p_,x_)+xy_, xy_,x_,q_) := if(isfree(b,xy) and isfree(b,x), if(q==2p, C_1*e^(((b+sqrt(b^2+4))/2)^(1/p)*x)+C_2*e^(((b-sqrt(b^2+4))/2)^(1/p)*x), C_1*exp(nsolve(x^q-b*x^p-1)*x) )); #dsolve(b_*y(p_,x_)+c_*xy_, xy_,x_,q_) := if(isfree(b,c,xy) and isfree(b,c,x), if(q==2p, if(b*b== -4c, C_1*exp((b/2)^(1/p)*x)*x+C_2*exp((b/2)^(1/p)*x), C_1*e^(((b+sqrt(b^2+4c))/2)^(1/p)*x)+C_2*e^(((b-sqrt(b^2+4c))/2)^(1/p)*x)), if(b+c==1, C_2*e^(x),0)+C_1*exp(nsolve(x^q-b*x^p-c)*x) ), if(p>=1 and -b/c==x, C_1*x) ); dsolve(y(p_,x_)+xy_, xy_,x_,q_) := gsolution(1,p,1,xy,x,q); dsolve(y(p_,x_)+c_*xy_, xy_,x_,q_) := gsolution(1,p,c,xy,x,q); dsolve(b_*y(p_,x_)+xy_, xy_,x_,q_) := gsolution(b,p,1,xy,x,q); dsolve(b_*y(p_,x_)+c_*xy_, xy_,x_,q_) := gsolution(b,p,c,xy,x,q); dsolve(y(p_,x_)+c_*xy_+d_, xy_,x_,q_) := if(isfree(c,d,xy) and isfree(c,d,x), gsolution(1,p,c,xy,x,q)-d/c, gsolution(1,p,c,xy,x,q)+psolution(1,p,c,d,xy,x,q) ); dsolve(y(p_,x_)+xy_+d_, xy_,x_,q_) := if(isfree(d,xy) and isfree(d,x), gsolution(1,p,1,xy,x,q)-d, gsolution(1,p,1,xy,x,q)+psolution(1,p,1,d,xy,x,q) ); dsolve(b_*y(p_,x_)+xy_+d_, xy_,x_,q_) := if(isfree(b,d,xy) and isfree(b,d,x), gsolution(b,p,1,xy,x,q)-d, gsolution(b,p,1,xy,x,q)+psolution(b,p,1,d,xy,x,q) ); dsolve(b_*y(p_,x_)+c_*xy_+d_, xy_,x_,q_) := if(isfree(b,c,d,xy) and isfree(b,c,d,x), gsolution(b,p,c,xy,x,q)-d/c, gsolution(b,p,c,xy,x,q)+psolution(b,p,c,d,xy,x,q) ); dsolve(b_*y(1,x_)^n_,y_,x_,2):= if(isfree(b,y) and isfree(b,x), if(n==2, C_2 - log(C_1 + b*x)/b,C_2 - (-(n - 1)* (C_1 + b*x))^(1/(1 - n) + 1)/(n - 2)/b )); dsolve(y(1,x_)^n_,y_,x_,2):= if(n==2, C_2 - log(C_1 + x), C_2 - (-(n - 1)* (C_1 + x))^(1/(1 - n) + 1)/(n - 2)); dsolve(xy_*y(1,x_)^2,xy_,x_,2):=sqrt(2)* inverseerf((sqrt(2 pi) *C_1* x + sqrt(2 pi)* C_2 )/pi); dsolve(b_*y(1,x_),y_,x_,2):=if(isfree(b,y),if(isfree(b,x), C_1+C_2*e^(b*x), C_2*integrate(exp(int(b,x)),x)+C_1 )); dsolve(b_*xy_*y(1,x_),xy_,x_,2):=if(b<0, 2C_1/sqrt(-b)*tanh(C_1*sqrt(-b)*(x+C_2)), if(isfree(b,xy) and isfree(b,x), 2C_1/sqrt(b)*tan(C_1*sqrt(b)*(x+C_2)) )); dsolve(xy_*y(1,x_),xy_,x_,2):= 2C_1*tan(C_1*(x+C_2)); dsolve(c_+y(1,x_),y_,x_,2):=if(isfree(c,y),if(isfree(c,x), C_1+C_2*e^x-c*x, C_1+C_2*e^(x)+integrate(exp(x)*int(exp(-x)*c,x),x) )); #dsolve(c_+b_*y(1,x_),y_,x_,2):=if(isfree(b,c,y),if(isfree(b,c,x), C_1+C_2*e^(b*x)-c*x/b, integrate(dsolve(c+b*y,y,x),x)+C_2 )); #dsolve(c_+b_*y(1,x_),y_,x_,2):=if(isfree(b,c,y),if(isfree(b,c,x), C_1+C_2*e^(b*x)-c*x/b, C_1+C_2*e^(b*x)+integrate(exp(b*x)*int(exp(-b*x)*c,x),x) )); dsolve(c_+b_*y(1,x_),y_,x_,2):=if(isfree(b,c,y),if(isfree(b,c,x), C_1+C_2*e^(b*x)-c*x/b, C_2+int(C_1*e^(int(b,x))+psolution(b,c,y,x,1),x) )); dsolve(xy_+y(1,x_),xy_,x_,2):= C_1*e^((1-sqrt(5))/2*x)+C_2*e^((1+sqrt(5))/2*x); dsolve(y(1,x_)+c_*xy_,xy_,x_,2):=if(isfree(c,xy), gsolution(1,c,xy,x,2) ); dsolve(b_*y(1,x_)+xy_,xy_,x_,2):=if(isfree(b,xy), gsolution(b,1,xy,x,2) ); dsolve(b_*y(1,x_)+c_*xy_,xy_,x_,2):=if(isfree(b,c,xy), gsolution(b,c,xy,x,2) ); dsolve(y(1,x_)+xy_+d_,xy_,x_,2):= gsolution(1,1,xy,x,2)+psolution(1,1,1,d,xy,x,2); dsolve(y(1,x_)+c_*xy_+d_,xy_,x_,2):= gsolution(1,c,xy,x,2)+psolution(1,1,c,d,xy,x,2); dsolve(b_*y(1,x_)+xy_+d_,xy_,x_,2):= gsolution(b,1,xy,x,2) +psolution(b,1,1,d,xy,x,2); dsolve(b_*y(1,x_)+c_*xy_+d_,xy_,x_,2):= gsolution(b,c,xy,x,2)+psolution(b,1,c,d,xy,x,2); #dsolve(b_*y(1,x_)+c_*xy_+d_,xy_,x_,2):=if(isfree(b,c,d,xy) and isfree(b,c,d,x), gsolution(b,c,xy,x,2)-d*x/b-d/c/b, if(b*b+4c==0, C_1*exp(b/2*x)+C_2*exp(b/2*x)*x+expand(exp(b/2*x)*x*int(exp(-b/2*x)*d,x)-exp(b/2*x)*int(d*exp(-b/2*x)*x,x)), gsolution(b,c,xy,x,2)+ expand(-e^((b-sqrt(b^2+4c))/2*x)*int(d*e^((-b+sqrt(b^2+4c))/2*x),x)+e^((b+sqrt(b^2+4c))/2*x)*int(d*e^((-b-sqrt(b^2+4c))/2*x),x)/sqrt(b*b+4c)) )); dsolve(a_*y_+b_*y_^n_,y_,x_,1):=If(isfree(a,b,y) , block(dsolve:=integrate(a,x), exp(dsolve)*(C_1+(1-n)*integrate(b*exp((n-1)*dsolve),x))^(1/(1-n)) ) ); dsolve(a_*y_+y_^n_,y_,x_,1):=If(isfree(a,n,y) , block(dsolve:=integrate(a,x), exp(dsolve)*(C_1+(1-n)*integrate(exp((n-1)*dsolve),x))^(1/(1-n)) ) ); dsolve(y_+y_^n_,y_,x_,1):= exp(x)*(C_1-exp((n-1)*x))^(1/(1-n)); dsolve(x_+y_, y_,x_,1) := C_1*exp(x)-x-1; dsolve(x_+y_, x_,y_,1) := C_1*exp(y)-y-1; #dsolve(a_*x_+y_, y_,x_) := If(isfree(a, x) and isfree(a, y), -a*x-a); #dsolve(x_+b_*y_,y_,x_) := If(isfree(b, x) and isfree(b, y), -1/b*x-1/b^2); #dsolve(a_*x_+b_*y_,y_,x_):=If(isfree(a,b, x) and isfree(a,b, y), -a/b*x-a/b^2); #dsolve(x_+y_+c_, y_,x_) := If(isfree(c,x) and isfree(c,y), -x-1-c); #dsolve(x_+b_*y_+c_, y_,x_) := If(isfree(b,c,x) and isfree(b,c,y), -1/b*x-1/b^2-c/b); #dsolve(a_*x_+y_+c_, y_,x_) := If(isfree(a,c,x) and isfree(a,c,y), -a*x-a-c); #dsolve(a_*x_+b_*y_+c_, y_,x_) := If(isfree(a,b,c,x) and isfree(a,b,c,y), -a/b*x-a/b^2-c/b); dsolve(f_^n_,y_,x_,q_) := if(has(f,x) and has(f,y) and isnumber(n), dsolve(pow(f,n),y,x,q) ); dsolve(b_*y_, y_,x_,1) := If(isfree(b,y), C_1*exp(integrate(b,x))); dsolve(b_*y_^n_, y_,x_,1) := If(isfree(b,y), ((1-n)*integrate(b,x)+C_1)^(1/(1-n)) ); dsolve(z_/(b_+c_), y_,x_,n_) := if((has(b,x) and has(c,y)) or (has(b,y) and has(b,x)), dsolve(b/z+c/z,x,y,n)=x^n/n!); dsolve(a_/(b_+c_), y_,x_,n_) := if((has(b,x) and has(c,y)) or (has(b,y) and has(b,x)), dsolve(b/a+c/a,x,y,n)=x^n/n!); dsolve(1/b_, y_,x_,n_) := if(has(b,y), dsolve(b,x,y,n)=x^n/n!); dsolve(y_,y_,x_,1) := C_1*exp(x); #dsolve(y(n_,x_),y_,x_) := C_1*exp(x); #dsolve(f_,y(x_)) := dsolve(replace(d(y(x),x)-f,y(x),y),y); #dsolve(a_=b_,y_):= if(has(a,ds(y,x,2)),dsolve(ds(y,x,2)-a+b,y,x,2), if(has(a,ds(y)),dsolve(ds(y)-a+b,y,x), if(has(a,dy),dsolve(dy/dx-a+b,y,x), dsolve(a-b,y) ))); #dsolve(y'=f_,y) := dsolve(f,y,x); #dsolve(y''=f_,y) := dsolve(f,y,x,2); #dsolve(dy/dx=f_,y) := dsolve(f,y,x); #dsolve(d(y(x_),x_)=f_,y(x_)) := dsolve(replace(f,y(x),y),y,x); #dsolve(ds(y_)=a_,y_) := dsolve(a,y,x); #dsolve(ds(y_,x_)=a_,y_) := dsolve(a,y,x); #dsolve(ds(y_,x_,q_)=a_,y_):= dsolve(a,y,x,q); #dsolve(a_+ds(y_,x_,q_),y_):= dsolve(-a,y,x,q); #dsolve(ds(y_,x_,q_)+z_,y_):= dsolve(-z,y,x,q); #dsolve(ds(y_,x_,q_)+f_+z_,y_):= dsolve(-f-z,y,x,q); #dsolve(a_+ds(y_,x_,q_)+z_,y_):= dsolve(-a-z,y,x,q); dsolve(a_+y(q_,x_),y_):= if(q<0 and hasno(a,y), -d(a,x,-q),dsolve(-a,y,x,q) ); dsolve(a_+b_*y(q_,x_),y_):= if(hasnot(a,y) and hasnot(a,y(x)) and hasnot(b,x), d(b,y,-q)= gsolution(0,y,x,q)-d(a,x,-q), if(q<0, dsolve(y+expand(d(a/b,x,-q)),y),dsolve(-expand(a/b),y,x,q) )); dsolve(c_+a_*xy_+b_*y(1,x_),xy_):= if(hasnot(c,xy) and a==d(b,x), C_1/b-int(c,x)/b, dsolve(-expand(c/b+a/b*xy),xy,x,1) ); dsolve(y(p_,x_)^n_+b_,y_):= dsolve(solve(replace(b,y(p,x),yy)+yy^n,yy),y,x,p); dsolve(a_*y(p_,x_)^n_+b_,y_):= dsolve(solve(expand(replace(b,y(p,x),yy)/a)+yy^n,yy),y,x,p); dsolve(a_+y(q_,x_),y(x_)):= if(q<0, dsolve(y+replace(toy(d(a,x,-q)),y(x),y),y),dsolve(-replace(a,y(x),y),y,x,q)); dsolve(a_+b_*y(q_,x_),y(x_)):= if(q<0, dsolve(y+expand(replace(toy(d(a/b,x,-q)),y(x),y)),y),dsolve(-expand(replace(a,y(x),y)/b),y,x,q)); dsolve(a_=b_,y_):=dsolve(toy(a-b),y); dsolve(integrates(f_,t_,a_,b_)=c_,y_) := dsolve(toy(d(integrates(f,t,a,b)-c,x))); dsolve(c_+integrates(f_,t_,a_,b_)+z_,y_) := dsolve(toy(d(integrates(f,t,a,b)+c+z,x)),y,x,1); dsolve(y(n_,t_)=a_,y_) := dsolve(toy(a),y,t,n); dsolve(x(n_,t_)=a_,x_) := dsolve(tox(a),x,t,n); #dsolve(b_+x(n_,t_),d_+y(n_,t_)):= (x=dsolve(-b,x,t,n) and y=dsolve(-d,y,t,n)); #dsolve(b_+x(n_,t_),d_+x_+y(n_,t_)):= block(xx:=dsolve(-b,x,t,n), x=xx and y=dsolve(-d-xx,y,t,n)); dsolve(b_+x(n_,t_),d_+y(m_,t_)):= if(hasnot(b,y(t)) and hasnot(d,x(t)), (x=dsolve(-b,x(t),t,n), y=dsolve(-d,y(t),t,m)), if(hasnot(b,y(t)),block(xx:=dsolve(-b,x(t),t,n), (x=xx, y=dsolve(-replace(d,x(t),xx),y(t),t,m))), if(hasnot(d,x(t)),block(xx:=dsolve(-d,y(t),t,m), (y=xx, x=dsolve(-replace(b,y(t),xx),x(t),t,n))) ))); dsolve(a_=b_,c_=d_):= dsolve(tox(a=b),toyt(c=d),x,y); dsolve(x(n_,t_)=b_,d_+y(m_,tt_),x_,y_):= block(bb:=replace(replace(b,x(t),x),y(t),y),dd:= replace(replace(-d,x(t),x),y(t),y), if(hasnot(bb,y),block(xx:=dsolve(bb,x,t,n), (x=xx, y=dsolve(replace(dd,x,xx),y,t,m))), if(hasnot(dd,x),block(xx:=dsolve(dd,y,t,m), (y=xx, x=dsolve(replace(bb,y,xx),x,t,n))), if(n==m, dsolve(bb,dd,x,y,n) )))); dsolve(x(m_,t_)=a_,y(n_,tt_)=c_,x_,y_):= if(hasnot(a,y), block(xx:=dsolve(a,x,t,m), (x=xx, y=dsolve(replace(c,x,xx),y,t,n))), if(hasnot(c,x), block(yy:=dsolve(c,y,t,n), (y=yy, x=dsolve(replace(c,y,yy),x,t,m))), dsolve(a,c,x,y,n) )); dsolve(x(1,t_)=a_*y_,y(1,tt_)=c_,x_,y_):=if(hasnot(a,x), block(xx:=dsolve(expand(a*replace(c,y,x(1,t)/a)),x,t,2), (x=xx, y=d(xx,t)/a))); dsolve(x(1,t_)=a_+y_,y(1,tt_)=c_,x_,y_):=if(hasnot(a,x), block(xx:=dsolve(expand(replace(c,y,x(1,t))),x,t,2), (x=xx, y=d(xx,t)-a))); dsolve(x(1,t_)=a_*y_+b_,y(1,tt_)=c_,x_,y_):=if(hasnot(a,b,x), block(xx:=dsolve(expand(a*replace(c,y,x(1,t)/a)),x,t,2), (x=xx, y=d(xx,t)/a-b/a))); dsolve(x(1,t_)=a_,y(1,tt_)=c_*x_,x_,y_):=if(hasnot(c,x), block(yy:=dsolve(expand(c*replace(a,x,y(1,t)/c)),y,t,2), (y=yy, x=d(yy,t)/c))); #dsolve(x(1,t_)=a_,y(1,tt_)=c_+x_,x_,y_):=if(hasnot(c,x), block(yy:=dsolve(expand(replace(a,x,y(1,t))),y,t,2), (y=yy, x=d(yy,t)-c))); #dsolve(x(1,t_)=a_,y(1,tt_)=b_+c_*x_,x_,y_):=if(hasnot(b,c,x), block(yy:=dsolve(expand(c*replace(a,x,y(1,t)/c)),y,t,2), (y=yy, x=d(yy,t)/c-b/c))); dsolve(ds(x_,t_)=f_,ds(y_,t_)=g_):= dsolve(x(1,t)=f,y(1,t)=g,x,y); dsolve(a_):=dsolve(replace(toy(a),y(x),y),y);