kill(all)$

maxima :appendix:fvm: integration of differential nd order( higher order differential), version 1.0
peter.vlasschaert@gmail.com, 31/10/2022

reference
=======

ref :antid,see website :https://petervlaschemeng.weebly.com/
--------------------------------------------------------------------------------------------------------------
integration : with load(antid),2021
=============================
26e)new: 05/08/2021:Calculus : Maxima : math :use antidiff = integration , version 1.0
download  (Maxima,code)       :maximamathuseantidiffversion12021.wxmx
download  (Maxima,png)         :maximamathuseantidiffversion12021outp
---------------------------------------------------------------------------------------------------------------

load packages, option
================

load(antid)$ratprint:false;

integration of differential : diff(T(x),x,nd),nd = integer
=========================================

expr1:diff(T(x),x,3);

a1:antid(expr1,x,x)[1];

a2:antid(a1,x,x)[1];

rem : use always : function =T(x), where x integration variable
T : example here we use.

boundary implimentation (final integration)

a2a:x=x+Δx/2;
a2b:x=x-Δx/2;
a4:at(a1,a2a)-at(a1,a2b);

a5:args(args(a4)[1])[1];

a6: antid(a5,x,x)[1];

a7:at(a6,a2a)-at(a6,a2b);

a8:args(args(a7)[1])[1];

a9:expand(integrate(a8,x,rhs(a2b),rhs(a2a)));

→ third order integration :diff(T(x),x,3)

my2integrate(expr1,s,s1,s2):=block([v1,v2,v3,v4,v5,v6,v7],
v1:antid(expr1,s,s)[1],
v2:at(v1,s2)-at(v1,s1),
v3:args(args(v2)[1])[1],
v4:antid(v3,s,s)[1],
v5:at(v4,s2)-at(v4,s1),
v6:args(args(v5)[1])[1],
v7:expand(integrate(v6,s,rhs(s1),rhs(s2))),
return([v2,v5,v7])
)$

→ local variables

a9a:[v1,v2,v3,v4,v5,v6,v7];

a10:my2integrate(expr1,x,a2b,a2a);

→ local variables

a10a:[v1,v2,v3,v4,v5,v6,v7];

1e)  first integration : diff(T(x),x,3) →
--------------------------------------------------

a11a:a10[1];

2e)  second integration : diff(T(x),x,2) →
-----------------------------------------------------

a11b:a10[2];

3e)  third integration : diff(T(x),x,1) →
-----------------------------------------------------

a11c:a10[3];

use: index variables.

my3integrate(expr1,s,s1,s2):=block([],
w[1]:expr1,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),
w[4]:args(args(w[3])[1])[1],
w[5]:antid(w[4],s,s)[1],
w[6]:at(w[5],s2)-at(w[5],s1),
w[7]:args(args(w[6])[1])[1],
w[8]:expand(integrate(w[7],s,rhs(s1),rhs(s2))),
return([w[3],w[6],w[8]])
)$

→ example: my3integrate

my3integrate(expr1,x,a2b,a2a);

my4integrate(expr1,s,s1,s2,nd):=block([ss:nd],
w[1]:expr1,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),
 ii:ss-2,   
w[3+ii]:args(args(w[3])[1])[1],
w[3+2*ii]:antid(w[3+ii],s,s)[1],
w[3+3*ii]:at(w[3+2*ii],s2)-at(w[3+2*ii],s1),
w[3+4*ii]:args(args(w[3+3*ii])[1])[1],
w[3+4*ii+1]:expand(integrate(w[3+4*ii],s,rhs(s1),rhs(s2))),
return([w[3],w[6],w[8]])
)$

rem : nd = 3, order of differential " diff(T(x),x,nd)"

→ example :my4integrate

my4integrate(expr1,x,a2b,a2a,3);

my5integrate(expr11,s,s1,s2,nd):=block([ss:nd,θ],
    
w[1]:expr11,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),
θ:ss-2,    
for ii:1 thru θ do (  
          w[3+ii]:args(args(w[3])[1])[1],
          w[3+2*ii]:antid(w[3+ii],s,s)[1],
          w[3+3*ii]:at(w[3+2*ii],s2)-at(w[3+2*ii],s1),
          w[3+4*ii]:args(args(w[3+3*ii])[1])[1]
                                  ),
w[3+4*θ+1]:expand(integrate(w[3+4*θ],s,rhs(s1),rhs(s2))),
/* result */
return([w[3],w[3+3*θ],w[3+4*θ+1]])
)$

→ local variable

a12:[θ,ss];

→ example :my5integrate

my5integrate(expr1,x,a2b,a2a,3);

→ fourth order 

my6integrate(expr11,s,s1,s2,nd):=block([ss:nd],
    
w[1]:expr11,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),

          w[4]:args(args(w[3])[1])[1],
          w[5]:antid(w[4],s,s)[1],
          w[6]:at(w[5],s2)-at(w[5],s1),
    
          w[7]:args(args(w[6])[1])[1],
          w[8]:antid(w[7],s,s)[1],
          w[9]:at(w[8],s2)-at(w[8],s1),
    
w[10]:args(args(w[9])[1])[1],
w[11]:expand(integrate(w[10],s,rhs(s1),rhs(s2))),
/* result */
return([w[3],w[6],w[9],w[11]])
)$

expr11:diff(T(x),x,4);

a13:my6integrate(expr11,x,a2b,a2a,4);

my7integrate(expr11,s,s1,s2,nd):=block([ss:nd],
    
w[1]:expr11,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),
     for ii:1 thru ss-2 do
                                   (
        
          w[3*ii+1]:args(args(w[3*ii])[1])[1],
          w[3*ii+2]:antid(w[3*ii+1],s,s)[1],
          w[3*ii+3]:at(w[3*ii+2],s2)-at(w[3*ii+1],s1)
    
                                     ),
qq:3*(ss-2)+3,
w[qq+1]:args(args(w[qq])[1])[1],
w[qq+2]:expand(integrate(w[qq+1],s,rhs(s1),rhs(s2))),
/* result */
return([w[3],w[6],w[9],w[qq+2]])
)$

a13:my7integrate(expr11,x,a2b,a2a,4);

my8integrate(expr11,s,s1,s2,nd):=block([ss:nd],
    
w[1]:expr11,
w[2]:antid(w[1],s,s)[1],
w[3]:at(w[2],s2)-at(w[2],s1),
     for ii:1 thru ss-2 do
                                   (
        
          w[3*ii+1]:args(args(w[3*ii])[1])[1],
          w[3*ii+2]:antid(w[3*ii+1],s,s)[1],
          w[3*ii+3]:at(w[3*ii+2],s2)-at(w[3*ii+1],s1)
    
                                     ),
qq:3*(ss-2)+3,
w[qq+1]:args(args(w[qq])[1])[1],
w[qq+2]:expand(integrate(w[qq+1],s,rhs(s1),rhs(s2))),
/* result */
qq1:makelist(w[3*ii],ii,1,ss-1),
qq2:flatten([qq1,w[qq+2]]),   
    
return(qq2)
)$

a14:my8integrate(expr11,x,a2b,a2a,4);

a15:my8integrate(diff(T(x),x,3),x,a2b,a2a,3);

a16:my8integrate(diff(T(x),x,2),x,a2b,a2a,2);

How to solve problem : expr11=diff(T(x),x)
================================

one problem : when expr11=diff(T(x),x)

→  exception problem : use if structure in maxima,ss=1

1e)  How to use if structure in maxima.
----------------------------------------------------

ref :https://stackoverflow.com/questions/66450066/how-to-use-maxima-if-then-else

2e) problem solved .
--------------------------

diffintegrate(expr11,s,s1,s2):=block([qq,qq1,ss],
    w[1]:expr11,            /* differential to integate */
     ss:args(expr11)[3],/*order of differential*/
if ss = 1 
     then 
           hh:[expand(integrate(w[1],s,rhs(s1),rhs(s2)))]              
     else   
         (w[2]:antid(w[1],s,s)[1],
           w[3]:at(w[2],s2)-at(w[2],s1),
           for ii:1 thru ss-2 do
                                   (        
                 w[3*ii+1]:args(args(w[3*ii])[1])[1],
                 w[3*ii+2]:antid(w[3*ii+1],s,s)[1],
                 w[3*ii+3]:at(w[3*ii+2],s2)-at(w[3*ii+1],s1)    
                                     ),
              qq:3*(ss-2)+3,
              w[qq+1]:args(args(w[qq])[1])[1],
              w[qq+2]:expand(integrate(w[qq+1],s,rhs(s1),rhs(s2))),
                /* result */
              qq1:makelist(w[3*ii],ii,1,ss-1),
              qq2:flatten([qq1,w[qq+2]]),     
            return(qq2))
)$

reason : diffintegrate construct (command)
----------------------------------------------------------
1e) needed to load : load(antid).
2e) integráte (= Maxima) can't handle higher order differential (except : first order differential,ss=1).
3e) don't forget :if then else , "( )" for the "else" to enclose the code. (otherwise : error)
4e) function(varibles):=block([local variable], code to execute, return(result)),also return : hh (for : ss=1)

b1:'diff(T(x),x,1);

→ integrate b1  (exception: ss=1 ,in diffintegrate)

c1:diffintegrate(b1,x,a2b,a2a);

b2:'diff(T(x),x,2);

→ integrate b2

c2:diffintegrate(b2,x,a2b,a2a);

b3:'diff(T(x),x,3);

→ integrate b3

c3:diffintegrate(b3,x,a2b,a2a);

b4:'diff(T(x),x,4);

→ integrate b4

c4:diffintegrate(b4,x,a2b,a2a);

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------