Derivatives
09-28-2022, 12:53 PM
Post: #1
 Eddie W. Shore Senior Member Posts: 1,606 Joined: Dec 2013
Derivatives
Any best practices when dealing with numerical first and second derivatives? The diff command is iffy at best in HP Prime PPL non-CAS.

Also, I working on being more comfortable with the CAS mode and make it my primary mode when I am working with the Prime.
09-29-2022, 12:51 PM (This post was last modified: 09-29-2022 01:09 PM by Arno K.)
Post: #2
 Arno K Senior Member Posts: 471 Joined: Mar 2015
RE: Derivatives
Hello Eddie,
diff and | (where) seem not to work, doesn't matter how many brackets are used as this is translated to ', that is (diff(x^3))|x=5 provides diff(125,5). You can use '(∂(x^3,x)|(x = 5))' which then provides the numeric result.
Arno
edit: diff(e^(2*x)+5*x^3-x,x,2,x=2) provides 60+2*e^2, that does the trick for higher derivatives
10-02-2022, 12:47 AM
Post: #3
 Eddie W. Shore Senior Member Posts: 1,606 Joined: Dec 2013
RE: Derivatives
Trying the second derivative in a program:

Code:
EXPORT DER2(f,v,n) BEGIN LOCAL d; d:=diff(f,v,2,v=n); RETURN d; END;

Home:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2('X^3','X',1) -> diff(diff(3.006003,2),0)

CAS:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2(x^3,x,1) -> diff(diff(3*x^2,2),0)

I hope that the next Prime update will allow for numerical differentiation for both first and second derivatives.
10-02-2022, 03:11 PM
Post: #4
 robmio Member Posts: 172 Joined: Jan 2020
RE: Derivatives
(10-02-2022 12:47 AM)Eddie W. Shore Wrote:  Trying the second derivative in a program:

Code:
EXPORT DER2(f,v,n) BEGIN LOCAL d; d:=diff(f,v,2,v=n); RETURN d; END;

Home:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2('X^3','X',1) -> diff(diff(3.006003,2),0)

CAS:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2(x^3,x,1) -> diff(diff(3*x^2,2),0)

I hope that the next Prime update will allow for numerical differentiation for both first and second derivatives.

Hello, try using this little program:
Code:
 #cas DER2(funz,grado,num):= BEGIN LOCAL dd, vrb, risultato; vrb:=lname(funz); vrb:=vrb(1); dd:=diff(funz,vrb,grado); risultato:=subst(dd,vrb=num); RETURN risultato; END; #end

Example:
DER2 (function, degree of derivation, number)
DER (t ^ 3,2,4) -> 24

Sincerely, robmio
10-02-2022, 04:37 PM
Post: #5
 robmio Member Posts: 172 Joined: Jan 2020
RE: Derivatives
(10-02-2022 12:47 AM)Eddie W. Shore Wrote:  Trying the second derivative in a program:

Code:
EXPORT DER2(f,v,n) BEGIN LOCAL d; d:=diff(f,v,2,v=n); RETURN d; END;

Home:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2('X^3','X',1) -> diff(diff(3.006003,2),0)

CAS:
DER2(X^3,X,1) -> Error: Bad argument value ("diff(f,v,2,v=n)")]
DER2(x^3,x,1) -> diff(diff(3*x^2,2),0)

I hope that the next Prime update will allow for numerical differentiation for both first and second derivatives.

another program uses the limits of the function:
Code:
 #cas DER2(funz,grado,num,ds):= BEGIN LOCAL dd, risultato; dd:=(t)->diff(funz(x),x,grado); risultato:=limit(dd(x),x,num,ds); RETURN risultato; END; #end

num --> value of the derivative
ds = -1 --> left limit
ds = +1 --> right limit
ds = 0 --> bidirectional limit

examples:
DER2((t)->t^3,2,4,0) --> 24
DER2((x)->Si(x),1,0,0) --> 1
DER2((x)->ln(x),1,0,1) --> +inf
DER2((x)->ln(x),1,0,-1) --> -inf
DER2((x)->ln(x),1,0,) --> +/-inf
DER2((t)->e^(-2*t),3,7,0) --> -8*exp(-14)
10-04-2022, 01:47 PM
Post: #6
 Arno K Senior Member Posts: 471 Joined: Mar 2015
RE: Derivatives
Ma program is smaller and insists in x being used:
#cas dif2(f,gr,val):=
BEGIN
return diff(f,x,gr,x=val);
END;
#end
and does the job.
Arno
10-05-2022, 09:44 AM
Post: #7
 robmio Member Posts: 172 Joined: Jan 2020
RE: Derivatives
(10-04-2022 01:47 PM)Arno K Wrote:  Ma program is smaller and insists in x being used:
#cas dif2(f,gr,val):=
BEGIN
return diff(f,x,gr,x=val);
END;
#end
and does the job.
Arno

Sincerely, robmio
10-05-2022, 09:52 AM
Post: #8
 robmio Member Posts: 172 Joined: Jan 2020
RE: Derivatives
(10-04-2022 01:47 PM)Arno K Wrote:  Ma program is smaller and insists in x being used:
#cas dif2(f,gr,val):=
BEGIN
return diff(f,x,gr,x=val);
END;
#end
and does the job.
Arno

Attention! If you use your program with Si (x) it returns undef. Is that okay?

dif2(Si(x),1,0) --> undef
10-05-2022, 04:21 PM
Post: #9
 Arno K Senior Member Posts: 471 Joined: Mar 2015
RE: Derivatives
Perhaps because dif2(Si(x),1,a) provides sin(a)/a and then 0 is used for a, without bothering with limits.
Arno
10-06-2022, 04:55 AM
Post: #10
 Eddie W. Shore Senior Member Posts: 1,606 Joined: Dec 2013
RE: Derivatives
(10-04-2022 01:47 PM)Arno K Wrote:  Ma program is smaller and insists in x being used:
#cas dif2(f,gr,val):=
BEGIN
return diff(f,x,gr,x=val);
END;
#end
and does the job.
Arno

This works well for CAS, and it's nice and compact. And the emulator likes this code too.
 « Next Oldest | Next Newest »

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