peter.vlasschaert@gmail.com,02/08/2017 'version 1.0'
1e) spherical coordinates (= find =>KE =kinetic energy=1/2*m*v^2)
2e) Lagrangian spherical coordinates = lag = KE - PE

ref:  schaum's outline series ,theory and problems
        of vector analysis and an introduction to tensor analysis
auth: Murray R.Spiegel 
rem: curvilinear coordinates.

zoomout : ctrl and scroll from the mouse

load 'packages'

kill(all)$
load("vector3d")$

menu:view :greek letters (make active)

position vector  'r'

assume(ρ>=0);

x:ρ*cos(phi)*sin(θ);
y:ρ*sin(phi)*sin(θ);
z:ρ*cos(θ);

r:[x,y,z];

depends on

depends([phi,ρ,θ],t);

velocity ,spherical coordinates = diff(r,t)

p1:diff(r,t);

components 'v'

p1a:part(p1,1);
p1b:part(p1,2);
p1c:part(p1,3);

velocity ^2  'dot product' =>v^2 = dot(v,v) 'p2'

p2:[p1a*p1a,p1b*p1b,p1c*p1c];
p3:p1*p1;

spherical coordinate system 'ortnogonal system'

dr = diff(r,ρ)*dρ+diff(r,phi)*dphi+diff(r,θ)*dθ

find : v(x,y,z)->v(ρ,phi,θ)

p4:diff(r,ρ);
p5:diff(r,phi);
p6:diff(r,θ);

find 2-norm : p4,p5,p6

p7:p4*p4$
p71:trigsimp(sqrt(part(p7,1)+part(p7,2)+part(p7,3)));
p8:p5*p5$
p81:trigsimp(sqrt(part(p8,1)+part(p8,2)+part(p8,3)));
p9:p6*p6$
p91:trigsimp(sqrt(part(p9,1)+part(p9,2)+part(p9,3)));

unit vectors  => (e_r,e_phi,e_θ) or (ee_r,ee_phi,ee_θ)

relation between : cartesian and spherical coordinates (vector components)

p10:e_r = [x,y,z]/ρ;
p11:e_φ= [cos(phi+%pi/2),sin(phi+%pi/2),0];

How to find e_θ from cross product
from figure  1 :              cross(e_r,e_phi) = -e_θ
           ' rule '           =>   cross(e_phi,e_r) = e_θ

p12:e_θ=trigsimp(cross(part(p11,2),part(p10,2)));

relation between : cartesian => spherical coordinates (equation)

p13:ee_r     = part(p10,2,1)*i+part(p10,2,2)*j+part(p10,2,3)*k;
p14:ee_φ    = part(p11,2,1)*i+part(p11,2,2)*j+part(p11,2,3)*k;
p15:ee_θ    = part(p12,2,1)*i+part(p12,2,2)*j+part(p12,2,3)*k;

find :i,j,k     from :p13,p14,15

menu : solve
first field       : p13,p14,p15
second field : i,j,k
=> trigsimp

sol:trigsimp(solve([p13,p14,p15], [i,j,k]));

p16:part(sol,1,1);
p17:part(sol,1,2);
p18:part(sol,1,3);

p19:R=expand(part(p16,2)*x+part(p17,2)*y+part(p18,2)*z);
p20:R=trigsimp(part(p19,2));

find : result easy to see result,all equations are good.(check)

depends(ee_r,t);

find :velocity = v = diff(R,t)

p21:'diff(R,t)=diff(part(p20,2),t);

p22 :'diff(ee_φ,t) = factor(diff(part(p14,2),t));
p23:'diff(ee_θ,t)  = factor(diff(part(p15,2),t));
p24:'diff(ee_r,t)  = factor(diff(part(p13,2),t));
p241:ratcoef(part(p24,2),diff(θ,t));
p242:ratcoef(part(p24,2),diff(phi,t));
p25:'diff(ee_r,t)  = p241*diff(θ,t)+p242*diff(phi,t);

find : diff(ee_r,t)  you need for p21

p26:part(p25,1)=ratsubst(part(p15,1), p241, part(p24,2));

p27:ev(p26,part(p14,2)=part(p14,1));

result  v ' spherical coordinates'

p28:ev(p21,p27);

p281:ratcoef(part(p28,2),ee_r);
p282:ratcoef(part(p28,2),ee_φ);
p283:ratcoef(part(p28,2),ee_θ);

 replace diff(R,t) => v (vector) components 'p281,p282,p283'

'velocity'   =>

p29:part(p28,1) = p281*ee_r+p282*ee_φ+p283*ee_θ;
p30 : ev(p29,part(p28,1)=v);

Kinetic Energy : Spherical coordinates (ρ,phi,theta)

p31:EK = 1/2*m*((p281)^2+(p282)^2+(p283)^2);

Potential Energie =V :Spherical coordinates (ρ,phi,theta),big V

depends(V,[ρ,phi,θ]);

p32:EP = V;

Lagrangian : cylindrical coordinates   (= lag) = EK-EP

p33:lag = part(p31,2)-part(p32,2);