HP Forums
Line integral, jacobian... - 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: Line integral, jacobian... (/thread-2992.html)



Line integral, jacobian... - salvomic - 02-02-2015 08:56 PM

hi all,
I need some hints to use with Prime:
curve integral (for scalar function by a curve)
line integral (vectorial camp by a curve)
flux integral

and also something to treat with Jacobian Matrix (where line are gradients).

Any programs, functions? hints to create my own program easily?

Thank a lot in advance!

Salvo


RE: Line integral, jacobian... - Han - 02-02-2015 10:42 PM

(02-02-2015 08:56 PM)salvomic Wrote:  hi all,
I need some hints to use with Prime:
curve integral (for scalar function by a curve)
line integral (vectorial camp by a curve)
flux integral

and also something to treat with Jacobian Matrix (where line are gradients).

Any programs, functions? hints to create my own program easily?

Thank a lot in advance!

Salvo

You should be able to do all of these in the CAS. For example, if C is the path from (0,0) to (1,1) then C is described by \( \vec{r}(t) = t\vec{i} + t\vec{j} \) where \( 0 \le t \le 1 \). If the force F is defined by \( \vec{F} = (3x-2y)\vec{i} + (4x+1)\vec{j} \) then
\[ \int \vec{F}\cdot d\vec{r} \]
can be computed by:

r:=[t,t];
dr:=diff(r,t);
f:=[3*x-2*y, 4*x+1];
ft:=subst(f,[x,y]=r);
int(dot(ft,dr),t,0,1);

If \( \vec{F} \) is path-independent (i.e. a gradient field; also known as conservative fields) then one can simply apply the fundamental theorem of calculus for vectors. For example, if
\[ \mathrm{grad}(f) = 2xy \vec{i} + (x^2+8y^3)\vec{j} \]
then you can do something like:

f1:=2*x*y; f2:=x^2+8y^3;

check if we actually have a real gradient field:

diff(f1,y) - diff(f2,x);

(simplify if needed; gradient field means difference should be 0). If we have a gradient field, i.e. \( \vec{F} = \mathrm{grad}(f) \), then we can find f by:

f:=int(f1,x);
dg:=diff(f,y)-f2;
g:=int(dg,y);
f:=simplify(f+g); // can optionally leave out simplify()
p:=[0,0];
q:=[1,1];
subst(f,[x,y]:=q)-subst(f,[x,y]=p);

Edit: A CAS program is really nothing more than copying the manual commands you use in the CAS view into a CAS-program, and making some minor edits and slapping #cas and #end around everything. So I recommend playing around with the CAS view, and once you have what you want, copy it into a program.


RE: Line integral, jacobian... - salvomic - 02-02-2015 11:05 PM

(02-02-2015 10:42 PM)Han Wrote:  You should be able to do all of these in the CAS. For example, if C is the path from (0,0) to (1,1) then ...

A CAS program is really nothing more than copying the manual commands you use in the CAS view into a CAS-program, and making some minor edits and slapping #cas and #end around everything. So I recommend playing around with the CAS view, and once you have what you want, copy it into a program.

thank you, Han, for this clear explanation. I'll read it again while try on CAS, and then I'll try to make one or more little program by myself, also if I'm still learning Prime's programming...
Your hint for subst() is very useful for my purpose.
Let's start...

Salvo


RE: Line integral, jacobian... - salvomic - 02-03-2015 08:55 PM

hi Han,
a little idea, following your precious advice (and thanks Snorre for a "C like" approach that's I like), to start; but these functions need some controls to avoid incorrect input and reset...

We can use two little programs:
intcur: to input scalar function (x,y,z), parametric form of a curve [r(t), r(t), r(t)], lower and high bound to get a curvilinear integral
intlin: to input vectorial function, parametric form of a curve, lower, high to get line integral...

EDIT: these programs now works with 2 or 3 components (parametric expression: [r(t), r(t), r(t)] or [r(t), r(t)])...

Code:

#cas
intcur(args):=
BEGIN
local argv,argc, a, b;
local f, r, dr, ft, s;

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;

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



RE: Line integral, jacobian... - salvomic - 02-04-2015 02:32 PM

here my hypothesis for Jacobian Matrix function...
It should works, I hope without errors (please, see if any).

Input: [f(1), f(2), ...], [x,y,...]

Salvo

Code:

#cas
jacob(args):=
// Matrice jacobiana by Salvo MiccichÈ
// input expr vettoriale, vettore variabili
BEGIN
local argv, argc, mat, f, var, fn, j, k,  gr, vd;
argv:=[args];
argc:=size(argv);
IF argc !=2 THEN
return "Input:[f1(x),f1(y),f1(z)...], [x,y,z,...]"; 
ELSE
f:=argv(1);
var:=argv(2);
fn:=size(f);
vd:=size(var);
mat:=makemat(0,fn,vd);
FOR j FROM 1 TO fn DO // gradienti
gr:=grad(f(j),var);
FOR k FROM 1 TO vd DO // elementi
mat[j,k]:=gr(k);
END; // for k
END; // for j
return mat;
END; // if-else

END;
#end

Now, please, help me to have a short program to calculate surface integrals and flux integral (Int(f.n)), thank you Smile


RE: Line integral, jacobian... - toshk - 09-07-2016 09:22 PM

Jacobian:
Transpose(diff(fn,[x,y,z])) or transpose(gradient([f1,f2,f3],[x,y,z])
trn(diff([x*y*z, y^2, x + z], [x, y, z]))

Laplacian:
divergence(gradient(f(x, y), [x y]),[x,y])


RE: Line integral, jacobian... - salvomic - 09-07-2016 10:35 PM

(09-07-2016 09:22 PM)toshk Wrote:  Jacobian:
Transpose(diff(fn,[x,y,z])) or transpose(gradient([f1,f2,f3],[x,y,z])
trn(diff([x*y*z, y^2, x + z], [x, y, z]))

Laplacian:
divergence(gradient(f(x, y), [x y]),[x,y])

yes, thanks

See also here my (and Han) solutions: Linear and curvilinear - Jacobian

laplacian(Expr, Vector) is also a command inside the Prime, now...

Salvo