kill(all)$

maxima: how to use table :calculation grad,div,curl  ,'spherical coordinates',version 1.0
peter.vlasschaert@gmail.com, 02/09/2021

ref:
==
new: 31/08/2021:maxima:differential volume element spherical coordinates for pde construct ,version 1.0
download  (Maxima,code)       :maximavolumedifferentialdatasphericalcoordversion12021
download  (Maxima,png)         :maximavolumedifferentialdatasphericalcoordversion12021outp
-----------------------------------------------------------------------------------------------------------------------------------------------
new: 01/09/2021:maxima:differential volume element cylindrical coordinates for pde construct ,version 1.0
download  (Maxima,code)       :maximavolumedifferentialdatacylindcoordversion12021
download  (Maxima,png)         :mamaximavolumedifferentialdatacylindcoordversion12021outp
new: 01/09/2021:maxima: how to use table :calculation grad,div,curl  ,'cylindrical coordinates',version 1.0
download  (Maxima,code)       :howtousetablecylindricalcoordversion12021
download  (Maxima,png)        :howtousetablecylindricalcoordversion12021outp
----------------------------------------------------------------------------------------------------------------------------------------------
 (2) unit vectors (spherical coordinates)
maxima : unit vector transformation (both direction),spherical coordinates,version 1
peter.vlasschaert@gmail.com,02/09/2021
-----------------------------------------------------------------------------------------------------------------------------------------------

book
====
(1) schaum 's outline series : Theory and Problems of Vector Analysis  ( general coordinate systems)

general packages,option
====================

load(lrats)$

packages vector (used :curl(A)),see 'below'
=============

load(vect)$

table :cylindrical coordinates (differential)
======================

assume(r>0,sin(θ)>0)$

spm:matrix(
        ["surface", "direction",    "incremental",  "scalefactor","unit vector"],
        [dθ·dφ·r^2·sin(θ),  r,  dr,dr/dr,er],
        [dr·dφ·r·sin(θ),    θ,  dθ·r, r*dθ/dθ,eθ],
        [dr·dθ·r,   φ,  dφ·r·sin(θ),dφ*r*sin(θ)/dφ,eφ]
           );

rem:r*dθ =[length]

spm1:args(spm);

spmt:table_form(spm)$

mathematics : →h : scale factors  (1)
(r,θ,z)  → (hr,hθ,hz)=(1,r,1)

ordergreat(er,eθ,eφ)$

gradient : incremental from table 'cyt'

gr1:∇(Φ)=1/spm[2,4]*'diff(Φ,r)*spm[2,5]+1/spm[3,4]*'diff(Φ,θ)*spm[3,5]+1/spm[4,4]*'diff(Φ,φ)*spm[4,5];

gr2:∇(Φ)=sum(1/spm[i,4]*'diff(Φ,spm[i,2])*spm[i,5],i,2,4);

ff:[r,θ,φ];

rem : don't forget comma :otherwise mistake

gr2a:makelist(ratcoeff(rhs(gr2),'diff(Φ,ff[i])),i,1,length(ff));

find : divergence :divergent cylindrical coordinates = ∇.vec(A)
----------------------------------------------------------------------------------
vec(A) =vector(A)

fist step : relation  unit vector ( dot product),ref:(2)
======================================

u1:er=sin(θ)*cos(φ)*ii+sin(θ)*sin(φ)*jj+cos(θ)*kk;
u1a:reverse(u1);
u2:eθ=cos(θ)*cos(φ)*ii+cos(θ)*sin(φ)*jj-sin(θ)*kk;
u2a:reverse(u2);
u3:eφ=cos(φ)*jj-sin(φ)*ii;
u3a:reverse(u3);

uu:[u1a,u2a,u3a];

→ rverse unit vectors ref(2)

uu1:ii=(er*sin(θ)+eθ*cos(θ))*cos(φ)-eφ*sin(φ);
uu1a:reverse(uu1);
uu2:jj=(er*sin(θ)+eθ*cos(θ))*sin(φ)+eφ*cos(φ);
uu2a:reverse(uu2);
uu3:kk=er*cos(θ)-eθ*sin(θ);
uu3a:reverse(uu3);

uur:[uu1a,uu2a,uu3a];

second step : ot product relation
===========================

m1:[er*er=1,eθ*eθ=1,eφ*eφ=1,er*eθ=0,er*eφ=0,eθ*eφ=0];/*dot product relation */

third step::differentation (unit ectors 'first step')
====================================

d1r:'diff(er,r)=diff(rhs(u1),r);
d2r:'diff(er,θ)=diff(rhs(u1),θ);
d2ra:lhs(d2r)=lratsubst(uu,rhs(d2r));
d3r:'diff(er,φ)=diff(rhs(u1),φ);
d3ra:lhs(d3r)=lratsubst(uu,rhs(d3r));

xd1:[d1r,d2ra,d3ra];

d1θ:'diff(eθ,r)=diff(rhs(u2),r);
d2θ:'diff(eθ,θ)=diff(rhs(u2),θ);
d2θa:lhs(d2θ)=lratsubst(uu,rhs(d2θ));
d3θ:'diff(eθ,φ)=diff(rhs(u2),φ);
d3θa:lhs(d3θ)=lratsubst(uu,rhs(d3θ));

xd2:[d1θ,d2θa,d3θa];

d1φ:'diff(eφ,r)=diff(rhs(u3),r);
d2φ:'diff(eφ,θ)=diff(rhs(u3),θ);
d2φa:lhs(d2φ)=lratsubst(uu,rhs(d2φ));
d3φ:'diff(eφ,φ)=diff(rhs(u3),φ);
d3φa:lhs(d3φ)=lratsubst(uu,rhs(d3φ));
d3φb:lhs(d3φ)=trigsimp(lratsubst([uu1,uu2],rhs(d3φa)));

'diff(eφ,φ,1), you need reverse version,see above.

xd3:[d1φ,d2φa,d3φb];

xd:table_form(transpose(matrix([xd1,xd2,xd3])))$

xda:flatten([xd1,xd2,xd3])$ /*differention result:list */

mv:vec(A)=Ar*er+Aθ*eθ+Aφ*eφ;

vec(A) : r → direction :differentation

mv1:diff(rhs(mv));;

mv1a:[er,eθ,eφ,Ar,Aθ,Aφ];

mv1b:map(del,mv1a);

vec(A) : r → direction :differentation
------------------------------------------------

mv1r:makelist(mv1b[i]='diff(mv1a[i],r),i,1,length(mv1a));

mv1ri:lratsubst(xda,mv1r);

mv1rr:lratsubst(mv1ri,mv1);

vec(A) : θ → direction :differentation
--------------------------------------------------

mv1θ:makelist(mv1b[i]='diff(mv1a[i],θ),i,1,length(mv1a));
mv1θi:lratsubst(xda,mv1θ);
mv1θθ:lratsubst(mv1θi,mv1);

vec(A) : φ→ direction :differentation
--------------------------------------------------

mv1φ:makelist(mv1b[i]='diff(mv1a[i],φ),i,1,length(mv1a));
mv1φi:lratsubst(xda,mv1φ);
mv1φφ:lratsubst(mv1φi,mv1);

s1:gr2a;

qx:m1;

q1:div(A)=expand(s1[1]*mv1rr+s1[2]*mv1θθ+s1[3]*mv1φφ);

depends(Ar,r,Aθ,θ,Aφ,φ);

q1a:lhs(q1)=ev(rhs(q1),diff);

q11a:copy(rhs(q1a));

to solve problem copy :rhs(q1a),manual

q2a:lhs(q1)=-(Aφ*eφ*er)/r-(Aθ*eθ*er)/r+('diff(Ar,r,1))*er*er-(Aφ*eφ*cos(θ)*eθ)/(r*sin(θ))+(('diff(Aθ,θ,1))*eθ*eθ)/r+(Ar*eθ*eθ)/r+(Aθ*eφ*cos(θ)*eφ)/(r*sin(θ))+(('diff(Aφ,φ,1))*eφ*eφ)/(r*sin(θ))+(Ar*eφ*eφ)/r;

q2b:lhs(q1)=expand(lratsubst(qx,rhs(q2a)));

check result books:(q2c)

q2c:lhs(q1)=1/r^2*'diff(r^2*Ar,r)+1/(r*sin(θ))*'diff(sin(θ)*Aθ,θ)+1/(r*sin(θ))*'diff(Aφ,φ);

q2c1:lhs(q1)=expand(ev(rhs(q2c),diff));

final check:q2b ? q2c1

q2cc:is(rhs(q2b)=rhs(q2c1));

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

Computation Curl(A) = ∇x A
=======================

declare(A,nonscalar)$

qq:curl(A);

don't write curl not as Curl

 qq1:express(qq);

scalefactors:cylindrical coordinates transformation
========================================

scalefactors([[r*cos(φ)*sin(θ),r*sin(φ)*sin(θ),r*cos(θ)],r,θ,φ])$

vector: point  vec(ρ) r*cos(φ)*sin(θ)*ii+r*sin(φ)*sin(θ)*jj+r*cos(θ)*kk →[r*cos(φ)*sin(θ),r*sin(φ)*sin(θ),r*cos(θ)]
vec(ρ)  : point on the sphere.( =coordinate)

qqq:express(qq);

s1:[A[r]=Ar,A[θ]=Aθ,A[φ]=Aφ];

qqq1:subst(s1,qqq);

other way

"∇xA="=qqq1[1]*er+qqq1[2]*eθ+qqq1[3]*ez;

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