Line integral, jacobian...
02-02-2015, 08:56 PM
Post: #1
 salvomic Senior Member Posts: 1,366 Joined: Jan 2015
Line integral, jacobian...
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?

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
02-02-2015, 10:42 PM (This post was last modified: 02-02-2015 10:57 PM by Han.)
Post: #2
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Line integral, jacobian...
(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?

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.

Graph 3D | QPI | SolveSys
02-02-2015, 11:05 PM
Post: #3
 salvomic Senior Member Posts: 1,366 Joined: Jan 2015
RE: Line integral, jacobian...
(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

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
02-03-2015, 08:55 PM (This post was last modified: 04-04-2015 12:35 PM by salvomic.)
Post: #4
 salvomic Senior Member Posts: 1,366 Joined: Jan 2015
RE: Line integral, jacobian...
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

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
02-04-2015, 02:32 PM
Post: #5
 salvomic Senior Member Posts: 1,366 Joined: Jan 2015
RE: Line integral, jacobian...
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

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
09-07-2016, 09:22 PM (This post was last modified: 09-07-2016 09:24 PM by toshk.)
Post: #6
 toshk Member Posts: 186 Joined: Feb 2015
RE: Line integral, jacobian...
Jacobian:
trn(diff([x*y*z, y^2, x + z], [x, y, z]))

Laplacian:
09-07-2016, 10:35 PM
Post: #7
 salvomic Senior Member Posts: 1,366 Joined: Jan 2015
RE: Line integral, jacobian...
(09-07-2016 09:22 PM)toshk Wrote:  Jacobian:
trn(diff([x*y*z, y^2, x + z], [x, y, z]))

Laplacian:

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

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
 « Next Oldest | Next Newest »

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