HP Forums
Line integral and curvilinear integral - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Line integral and curvilinear integral (/thread-3851.html)



Line integral and curvilinear integral - salvomic - 05-15-2015 08:17 PM

hi all,
here there are two programs (CAS) to calculate Line integral (for vectorial functions fields) and Curvilinear Integral (for scalar functions).


intcur: INPUT a scalar function (x,y,z), a parametric form of a curve [r(t), r(t), r(t)], lower and high bound and the programs returns curvilinear integral
intlin: INPUT a vectorial function, a parametric form of a curve (as above), lower and high bound and the program returns linear integral.

These programs work with 2 or 3 components (parametric expression: [r1(t), r2(t), r3(t)] or [r1(t), r2(t)])...

Examples:
1.0 to find the curvilinear integral of z in a circle (parametric: x=COS(t), y=SIN(t), z=t) from 0 to 2π
intcur(z, [COS(t), SIN(t), t], 0, 2*π) -> 2*√2*π^2
2. to find the line integral of F=‹x*SIN(y), y› along the path ‹t, t^2› from -1 to 2
intlin([x*SIN(y), y], [t, t^2], -1,2) -> (15/2)+(COS(1)-COS(4))/2

Enjoy!

Salvo Micciché

Code:

#cas
intcur(args):=
    BEGIN
    local argv,argc, a, b;
    local f, r, dr, ft, s,t;
    purge(t);
    argv:=[args];
    argc:=size(argv);
    IF argc !=4 THEN
    return "Input:f(x,y,z), [r(t),r(t),r(t)] ,low, high";
     ELSE
    f:=argv(1);
    r:=argv(2);
    a:=argv(3);
    b:=argv(4);
    dr:=diff(r,t);
    s:= size(argv(2));
    ft:= IFTE( s==3, subst(f,[x,y,z]=r), subst(f,[x,y]=r) );
    return int(dot(ft,l2norm(dr)),t,a,b);
    END;

END;
#end

...
Code:

#cas
intlin(args):=
BEGIN
local argv, argc, a, b;
local f, r, dr, ft,s, t;
purge(t);
argv:=[args];
argc:=size(argv);
IF argc !=4 THEN
return "Input:[x,y,z], [r(t),r(t),r(t)] ,low, high"; 
 ELSE
f:=argv(1);
r:=argv(2);
a:=argv(3);
b:=argv(4);
dr:=diff(r,t);
s:= size(argv(2));
ft:= IFTE( s==3, subst(f,[x,y,z]=r), subst(f,[x,y]=r) );
return int(dot(ft,dr),t,a,b);
END;

END;
#end

EDIT: put above a slightly new code, in which t is a local variable that's now purged first to being used in the integral calculus, to avoid to leave a global variable in CAS Vars.