HP Forums
del operators ( ∇ × A , ∇ ⋅ A, ∇f) in (polar coordinates ) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: del operators ( ∇ × A , ∇ ⋅ A, ∇f) in (polar coordinates ) (/thread-6827.html)



del operators ( ∇ × A , ∇ ⋅ A, ∇f) in (polar coordinates ) - toshk - 09-10-2016 10:09 PM

gradc(f)==gradient in cylindrical ∇f
grads(f)==gradient in spherical
divc(f)==divergence in cylindrical ∇ ⋅ f,
divs(f)==divergence in spherical
curlc(f)==curl in cylindrical ∇ × f
curls(f)==curl in spherical

notation: standard == prime input
(ρ, φ, z) ==> (r,x,z)--------cylindrical
(r, θ, φ) ==> (r,x,z)--------spherical

curls([r*cos(x), sin(x)*z, r*z*cos(x)])

Code:

#pragma mode( separator(.,;) integer(h32) )
#cas
//(ρ, φ, z)==(r,x,z)
gradc(f):=
BEGIN
local tem1,tem2,tem3;
tem1:=diff(f,r);
tem2:=(1/r)*diff(f,x)
tem3:=diff(f,z);
return [tem1,tem2,tem3];
END;

//(r, θ, φ)==(r,x,z)
grads(f)
BEGIN
local tem1,tem2,tem3;
tem1:=diff(f,r);
tem2:=(1/r)*diff(f,x);
tem3:=(1/(r*sin(x)))diff(f,z);
return [tem1,tem2,tem3];
END;

//(ρ, φ, z)==(r,x,z)
divc(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/r)*diff((r*f[1]),r);
tem2:=(1/r)*diff(f[2],x);
tem3:= diff(f[3],z);
return [tem1,tem2,tem3];  
END;

//(ρ, φ, z)==(r,x,z)
divs(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/r^2)*diff((r^2)*f[1],r);
tem2:=(1/(r*sin(x)))*diff(sin(x)*f[2],x);
tem3:=(1/(r*sin(x)))*diff(f[3],z);
return [tem1,tem2,tem3];  
END;

curlc(f)
//(ρ, φ, z)==(r,x,z)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/r)*diff(f[3],x)-diff(f[2],z);
tem2:=diff(f[1],z)-diff(f[3],r);
tem3:= (1/r)*(diff(r*f[2],r)-diff(f[1],x));
return [tem1,tem2,tem3];   
END;

curls(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/(r*sin(x)))*(diff(sin(x)*f[3],x)-diff(f[2],z));
tem2:=(1/r)*(((1/sin(x))*diff(f[1],z))-diff(r*f[3],r));
tem3:= (1/r)*(diff(r*f[2],r)-diff(f[1],x));
return [tem1,tem2,tem3];   
END;

#end



RE: del operators ( ∇ × A , ∇ ⋅ A, ∇f) in (polar coordinates ) - toshk - 09-11-2016 06:02 PM

notation: almost standard , except 'θ' is a reserved real variable on prime...any work around that?
(ρ, φ, z)--------cylindrical
(r, θ, φ) ==> (r,x,φ)--------spherical

Code:

#pragma mode( separator(.,;) integer(h32) )
#cas
//(ρ, φ, z)
gradc(f)
BEGIN
local tem1,tem2,tem3;
tem1:=diff(f,'ρ');
tem2:=(1/ρ)*diff(f,'φ')
tem3:=diff(f,'z');
return [tem1,tem2,tem3];
END;


//(r,θ,φ)==(r,x,φ)
grads(f)
BEGIN
local tem1,tem2,tem3;
tem1:=diff(f,r);
tem2:=(1/r)*diff(f,x);
tem3:=(1/(r*sin(x)))diff(f,'φ');
return [tem1,tem2,tem3];
END;

//(ρ, φ, z)
divc(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/ρ)*diff((ρ*f[1]),'ρ');
tem2:=(1/ρ)*diff(f[2],'φ');
tem3:= diff(f[3],z);
return [tem1,tem2,tem3];  
END;

//(r, θ, φ)==(r,x,φ)
divs(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/r^2)*diff((r^2)*f[1],r);
tem2:=(1/(r*sin(x)))*diff(sin(x)*f[2],x);
tem3:=(1/(r*sin(x)))*diff(f[3],'φ');
return [tem1,tem2,tem3];  
END;

curlc(f)
//(ρ, φ, z)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/ρ)*diff(f[3],'φ')-diff(f[2],z);
tem2:=diff(f[1],z)-diff(f[3],'ρ');
tem3:= (1/ρ)*(diff(ρ*f[2],'ρ')-diff(f[1],'φ'));
return [tem1,tem2,tem3];   
END;

//(r, θ, φ)==(r,x,φ)
curls(f)
BEGIN
local tem1,tem2,tem3;
tem1:=(1/(r*sin(x)))*(diff(sin(x)*f[3],x)-diff(f[2],'φ'));
tem2:=(1/r)*(((1/sin(x))*diff(f[1],'φ'))-diff(r*f[3],r));
tem3:= (1/r)*(diff(r*f[2],r)-diff(f[1],x));
return [tem1,tem2,tem3];   
END;
#end