Post Reply 
Fractional derivative
10-28-2022, 11:35 AM
Post: #1
Fractional derivative
hello, I propose a program that calculates the fractional derivatives. Comments and corrections to the program are appreciated. Thank you very much, robmio:

DerFraz((variable)->f(variable),n,a) -->

--> where "n" is the degree of derivation, while "a" is the lower limit of the integral of the "fractional derivative of Riemann-Liouville" (see https://www.youtube.com/watch?v=2dwQUUDt...orphocular). Wolfram Mathematica 13.1 adopts "a=0".

for example, the semiderivative of x^2 corresponds to:

DerFraz((x)->x^2,1/2,0) --> (8*x*sqrt(x))/(3*pi)

and here is the reverse process:

DerFraz((x)->(8*x*sqrt(x))/(3*pi),-1/2,0) --> x^2.

Code:

#cas
DerFraz(ff,pp,aa):=
//ff --> (x)->funzione
//aa: estremo inferiore dell'intergrale;
//pp grado di derivazione
BEGIN
LOCAL kappa, fnz, uu;
uu:=lname(ff)(1);
kappa:=MAX(0,CEILING(pp));
IF type(pp)==DOM_INT AND SIGN(pp)==1 THEN
kappa:=pp+1;
fnz:=(t)->(1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,t);
ELSE
fnz:=(t)->(1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,t);
END;
IF SIGN(pp)==−1 THEN
RETURN subst(fnz(t),t,uu);
ELSE
IF pp==0 THEN
RETURN ff(uu);
ELSE
RETURN subst(diff(fnz(t),t,kappa),t,uu);
END;
END;
END;
#end
Find all posts by this user
Quote this message in a reply
10-29-2022, 03:40 PM
Post: #2
RE: Fractional derivative
here is the modified program:

Code:

#cas
DerFraz(ff,pp,aa):=
//ff --> (x)->funzione
//aa: estremo inferiore dell'intergrale;
//pp grado di derivazione
BEGIN
LOCAL kappa, fnz, uu;
uu:=lname(ff)(1);
kappa:=MAX(0,CEILING(pp));
IF type(pp)==DOM_INT AND SIGN(pp)==1 THEN
kappa:=pp+1;
fnz:=(t)->((1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,
assume(t>0 AND t>x)));
fnz:=(x)->fnz(purge(x));
ELSE
fnz:=(t)->(1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,
assume(t>0 AND t>x));
fnz:=(x)->fnz(purge(x));
END;
IF SIGN(pp)==−1 THEN
RETURN subst(fnz(t),t,uu);
ELSE
IF pp==0 THEN
RETURN ff(uu);
ELSE
RETURN subst(diff(fnz(t),t,kappa),t,uu);
END;
END;
END;
#end
Find all posts by this user
Quote this message in a reply
10-29-2022, 04:17 PM
Post: #3
RE: Fractional derivative
Quote:fnz:=(x)->fnz(purge(x));

What does fnz(x) do?
Recursion without a base case ... does it cause infinite recursions?

Also, why purge(x)?
It seems x is function argument, thus already local variable.
Find all posts by this user
Quote this message in a reply
10-29-2022, 07:05 PM
Post: #4
RE: Fractional derivative
(10-29-2022 04:17 PM)Albert Chan Wrote:  
Quote:fnz:=(x)->fnz(purge(x));

What does fnz(x) do?
Recursion without a base case ... does it cause infinite recursions?

Also, why purge(x)?
It seems x is function argument, thus already local variable.

with this instruction I tried not to make the "x" variable appear in the HP Prime CasVar. In this way, however, I cannot calculate some derivatives such as "DerFraz((x)->exp(x), 23 / 100,0). Can you help me?
Find all posts by this user
Quote this message in a reply
10-31-2022, 12:21 PM
Post: #5
RE: Fractional derivative
(10-29-2022 04:17 PM)Albert Chan Wrote:  
Quote:fnz:=(x)->fnz(purge(x));

What does fnz(x) do?
Recursion without a base case ... does it cause infinite recursions?

Also, why purge(x)?
It seems x is function argument, thus already local variable.

In the end I prefer to use the "assume()" statement outside the program. Whenever I want to calculate the fractional derivative, on the "cas" screen I write: assume (t>0 and t>x), and the program works fine.

Code:

#cas
DerFraz(ff,pp,aa):=
//ff --> (x)->funzione
//aa: estremo inferiore dell'intergrale;
//pp grado di derivazione
BEGIN
LOCAL kappa, fnz, uu, Fnz, presenza,
posizionee;
uu:=lname(ff)(1);
kappa:=MAX(0,CEILING(pp));
presenza:=lvar(ff(uu));
posizionee:=POS(presenza,exp(x));
IF posizionee≠0 THEN
ff:=(uu)->subst(ff(uu),exp(uu),
exp(uu-t)*exp(t));
END;
IF type(pp)==DOM_INT AND SIGN(pp)==1 THEN
kappa:=pp+1;
fnz:=((1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,t));
Fnz:=(t)->fnz;
ELSE
IF SIGN(pp)≠0 THEN
fnz:=(1/Gamma(kappa-pp))*
int((t-x)^(kappa-pp-1)*ff(x),x,aa,t);
Fnz:=(t)->fnz;
END;
END;
IF SIGN(pp)==−1 THEN
RETURN subst(Fnz(t),t,uu);
ELSE
IF pp==0 THEN
RETURN ff(uu);
ELSE
RETURN subst(diff(Fnz(t),t,kappa),t,uu);
END;
END;
END;
#end


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 




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