Post Reply 
Line integral and curvilinear integral
05-15-2015, 08:17 PM (This post was last modified: 11-06-2017 04:10 PM by salvomic.)
Post: #1
Line integral and curvilinear integral
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)])...

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.

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)