############################################################################### # # The procedure varder calculates the variational derivative of # a functional L with respect to u. # ############################################################################### varder:=proc(L,u,x) option `Authors: B. Deconinck`; local N,k,lag,v,diffvec,m; N:=hdifforder(L,u,x); # N is the order of the highest derivative of u w.r.t. x occuring in L lag:=L; for k from N by -1 to 1 do lag:=subs(diff(u,[seq(x,j=1..k)])=v[k],lag) od; lag:=subs(u=v[0],lag); diffvec:=[seq(diff(lag,v[k]),k=0..N)]; diffvec:=map2(subs,v[0]=u,diffvec); diffvec:=map2(subs,[seq(v[k]=diff(u,[seq(x,m=1..k)]),k=1..N)],diffvec); # The last result serves as the output of the procedure (expand(diffvec[1]+add((-1)^k*diff(diffvec[k+1],[seq(x,m=1..k)]),k=1..N))) end: ############################################################################### # # The procedure hdifforder finds the order of the highest # derivative of u w.r.t. x occuring in L. # ############################################################################### hdifforder:=proc(L,u,x) option `Authors: B. Deconinck`; local k,lijst,flag; k:=0; flag:=1; lijst:=[]; while flag=1 do if has(L,diff(u,lijst)) then lijst:=[op(lijst),x]; k:=k+1 else flag:=0 fi od; # the last result serves as the output of the procedure if k=0 then 0 else k-1 fi; end: ############################################################################### # # The procedure varder calculates the higher-order # variational derivative of a functional L with respect to u. # This procedure cannot be used to compute the variational # derivative. We require n to be at least 1. # ############################################################################### vardern:=proc(L,u,n,x) option `Authors: B. Deconinck`; local N,k,lag,v,diffvec,m; N:=hdifforder(L,u,x); if N0 and flag1=0 then flag1:=i; fi; od; if flag1<>0 then newA:=linalg[pivot](newA,flag1,step); if step=1 then newB:=linalg[matrix]([linalg[row](newA,flag1)]); else newB:=linalg[stackmatrix](B,linalg[row](newA,flag1)); fi; if rowdims=1 then return(newB); else newA:=linalg[delrows](newA,flag1..flag1); RRED(newA,step+1,newB,maxsstep); fi; else RRED(newA,step+1,newB,maxsstep); fi; end: ################################################################################################################################# # # INT is used to compute integrals of expressions that depend on unknown functions that depend on an independent variable x. # All terms that are total derivatives are integrated. # The order of the highest derivative in the remaining integral is minimized. # ################################################################################################################################# INT:=proc(EE,x) option `Authors: M. Nivala`; local dcheck,limset,eqnset2,RE,param, eqnset,v,slnset,novan,Flist,intnogood,nogood,subDFL,intxset,sln,Esub,Fsub,DFLsub,termlist,FL,xset,E,u,goo,A,Ar,Ag,bob,syst,i,j,m,DFL,s,n,fresult,result,a,E1,DF1,R,subrules,b,EL,F1,F,DF,k; E:=expand(eval(EE)); #determine the unknown functions u:=whatfun(E); if u=[NULL] then return(int(E,x)) fi; #check if E is exact #dcheck:=[seq(varder(E,u[i],x),i=1..nops(u))]; #if dcheck=[seq(0,i=1..nops(u))] then #return(expand(int(E,x))); #fi; #convert E to a list if not(whattype(E)=`+`) then EL:=[E]; else EL:=convert(E,`list`); fi; #remove terms which have no functional or x dependence to be integrated directly xset:={NULL}; for k in EL do if not(has(k,u)) or not(has(k,x)) then xset:={op(xset),k}; fi; od; xset:=expand(convert(xset,`+`)); intxset:=int(xset,x); E:=expand(eval(E-xset)); if not(whattype(E)=`+`) then EL:=[E]; else EL:=convert(E,`list`); fi; #FL is a list of terms from the homotopy integral of E FL:=vechomotopyintegral(E,u,x); #print(FFFFFFF,FL); if FL=[NULL] then return(int(E,x)+intxset); fi; #DFL is the derivative of FL with respect to x DFL:=[seq(expand(diff(FL[n],x)),n=1..nops(FL))]; #form substitution rules #subDFL is for substitution rules subDFL:={NULL}; for k in DFL do if not(whattype(k)=`+`) then subDFL:={op(subDFL),k}; else subDFL:={op(subDFL),op(k)}; fi; od; termlist:=[op({op(EL),op(FL),op(subDFL)})]; #remove constant coefficients termlist:=[op({seq(SPLIT(termlist[i],x)[1],i=1..nops(termlist))})]; #orders termlist according to the order of the highest derivative of each element, from highest to lowest, groouping those of the #same order termlist:=dorderlist(termlist,u,x);#print(dord,termlist); #for consistency, implement an ordering of funtions and their derivatives according to lexorder for those terms which are of the #same differential order termlist:=[seq(op(funlexorder(termlist[i])),i=1..nops(termlist))];#print(orderedsub,termlist); #perform the substitutions subrules:=(seq(termlist[n]=b[n],n=1..nops(termlist))); #order subrules according to number of products in each term subrules:=torderset({subrules});#print(SUBRULES,subrules); Esub:=SUBS(subrules,E,x); DFLsub:=[seq(SUBS(subrules,DFL[i],x),i=1..nops(DFL))]; #R is what remains after integrating E #R is optimized, removing higest order derivaites first R:=expand(Esub-sum(a[m]*DFLsub[m],m=1..nops(DFL)));#print(E-sum(a[m]*DFL[m],m=1..nops(DFL))); R:=collect(R,{seq(b[m],m=1..nops(termlist))});#print(RRR,R); #form the linear system to be solved syst:={NULL}; for m from 1 to nops(termlist) do if has(coeff(R,b[m]),[seq(a[n],n=1..nops(DFL))]) then syst:=[op(syst),coeff(R,b[m])=0]; fi; od; #A is the overdetermined system for the coefficients, a #Ar is the first nops(a) linearly independent rows of A A:=linalg[genmatrix](syst,[seq(a[j],j=1..nops(DFLsub))],flag);#print(AAAA,A); Ar:=RRED(A,1,A,nops(DFLsub)+1);#print(ArAr,Ar); slnset:=linalg[backsub](Ar,`false`,`v`);#print(slnset); sln:=seq(a[m]=slnset[m],m=1..nops(DFLsub));#print(solution,sln); sln:=eval(sln,v=0);#print(solution,sln); assign(sln); #all terms which were not integrated using homotopy, attempt to integrate each independently without homotopy nogood:=expand(E-add(a[i]*DFL[i],i=1..nops(DFL)));#print(nogood); if not(whattype(nogood)=`+`) then nogood:=[nogood]; else nogood:=convert(nogood,`list`); fi; intnogood:=expand(add(int(nogood[i],x),i=1..nops(nogood)));#print(intnogood); #print(expand(E-add(a[i]*DFL[i],i=1..nops(DFL))+xset+novan+RE),"Was Integrated By Maple"); fresult:=add(a[j]*FL[j],j=1..nops(FL))+combine(intnogood)+intxset;#print(fdfdfdfd,fresult); unassign(a); #check if correct if simplify(expand(EE-diff(fresult,x)))<>0 then print("No integration done."); return(int(E,x)+intxset) else return(fresult); fi; end: ######################################################################################################## # # ouputs the expression G modulo total derivatives # ######################################################################################################## DerivativeMod:=proc(G,x) local IG,n,intpart,Glist; IG:=INT(G,x); if not(whattype(IG)=`+`) then Glist:=[IG]; else Glist:=convert(IG,`list`); fi; intpart:=0; for n from 1 to nops(Glist) do if has(Glist[n],`int`) then intpart:=diff(Glist[n],x); fi; od; intpart; end: ######################################### # # checks if INT is correct # ######################################### INTcheck:=proc(E,F,x) normal(expand(E-diff(F,x))); end: ############################################## # # # ############################################## chi:=proc(n,x) option remember; local result; if n=0 then result:=-u(x); else if n=1 then result:=diff(u(x),x); else result:=-diff(chi(n-1,x),x)-add(chi(n-k-2,x)*chi(k,x),k=0..n-2); fi; fi; result; end: