How to define the derivative of a function as a new function in Maxima

Click For Summary

Discussion Overview

The discussion revolves around defining the derivative of a function as a new function in Maxima, a computer algebra system. Participants explore issues related to syntax, evaluation of derivatives, and error messages encountered while attempting to implement these definitions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant attempts to define a function and its derivative but encounters an error when trying to evaluate the derivative at a specific point.
  • Another participant suggests that the issue arises because the right-hand side of the derivative definition does not evaluate until the definition is used, leading to errors when called with numerical values.
  • A proposed solution involves localizing the derivative variable and substituting in the value, although this may lead to inefficiencies.
  • An alternative solution is offered using a different syntax that avoids the need for re-evaluation of the derivative each time it is called.
  • Some participants express uncertainty about the commonality of Maxima and share experiences with other software packages.
  • Links to external resources, such as mailing lists and forums, are provided for further assistance.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the errors encountered and the need for proper syntax in defining derivatives, but there is no consensus on the best approach to resolve these issues, as multiple solutions are proposed.

Contextual Notes

Participants note that the evaluation of derivatives in Maxima can lead to errors if not handled correctly, and there are limitations in the software's handling of certain expressions when numerical values are involved.

Who May Find This Useful

This discussion may be useful for users of Maxima or those interested in computer algebra systems, particularly in the context of defining and working with derivatives in programming environments.

HotMintea
Messages
42
Reaction score
0
For example,

F(x) := x^2;
Fx(x) := diff(F(x),x,1);

didn't seem to work, since

Fx(3);

returned an error.

Any help would be appreciated.
 
Physics news on Phys.org
Okay, I'll be more specific. Basically, I'd like to give names to the derivatives of functions. The following is how I tried.A(x):=A1*exp(%i*k*x)+A2*exp(-%i*k*x);
Ax(x):=diff(A(x), x,1);
B(x):=A2*exp(-%i*k*x);
Bx(x):=diff(B(x),x,1);
C(x):=C1*exp(j*x)+C2*exp(-j*x);
Cx(x):=diff(C(x),x,1);

A(-a/2)=C(-a/2);
B(a/2)=C(a/2);
Ax(-a/2)=Cx(-a/2);
Bx(a/2)=Cx(a/2);After that I'd like to solve the last 4 equation for A2, C1, and C2 in terms of A1. However, I already have an error for the last 2 expressions [ ev(...) = ev(...) ]. Judging from the error message:

diff: second argument must be a variable; found -a/2
#0: Ax(x=-a/2)
-- an error. To debug this try: debugmode(true);
diff: second argument must be a variable; found a/2
#0: Bx(x=a/2)
-- an error. To debug this try: debugmode(true);

I think the error comes from how I defined Ax(x), Bx(x), and Cx(x).But I still cannot figure out how to fix it. Any help would be appreciated.
 
Are we supposed to know the syntax for 'Maxima'? Is it a very common software package?
 
@Dickfore: Maxima is one of the more common opensource computer algebra systems out there.

@HotMintea: I've never really used Maxima much - apart from via Sage.
The problem in your code is that the right hand side does not get evaluated until the definition is used. This is a problem because it has to recalculate the derivative everytime AND it gives an error when called with a number:
Fx(2) --> diff(F(2), 2) --> error

The second issue (the error) can be solved by localizing the derivative variable then substituting in the value, e.g.
Fx(x):=block([y], subst([y=x], diff(F(y),y)));

But then Maxima has to go through that whole mess everytime the derivative Fx is called. A better solution is to use the construct:

Fx(x) := ''(diff(F(x),x));

I found most of this on the thread
http://www.math.utexas.edu/pipermail/maxima/2007/004706.html

It seems that there aren't many Maxima users on this forum. Maybe the above mailing list (http://maxima.sourceforge.net/maximalist.html) would be a better place if you have questions. Also try http://stackoverflow.com or one of the Sage forums such as http://ask.sagemath.org or https://groups.google.com/forum/#!forum/sage-support
 
Last edited by a moderator:
Simon_Tyler said:
The problem in your code is that the right hand side does not get evaluated until the definition is used. This is a problem because it has to recalculate the derivative everytime AND it gives an error when called with a number:
Fx(2) --> diff(F(2), 2) --> error

Thanks for the explanation. Now I understand why.

Simon_Tyler said:
The second issue (the error) can be solved by localizing the derivative variable then substituting in the value, e.g.
Fx(x):=block([y], subst([y=x], diff(F(y),y)));

But then Maxima has to go through that whole mess everytime the derivative Fx is called. A better solution is to use the construct:

Fx(x) := ''(diff(F(x),x));

It definitely worked.

Simon_Tyler said:
I found most of this on the thread
http://www.math.utexas.edu/pipermail/maxima/2007/004706.html

It seems that there aren't many Maxima users on this forum. Maybe the above mailing list (http://maxima.sourceforge.net/maximalist.html) would be a better place if you have questions.

I tried out the mailing list archive. It seems great.

Simon_Tyler said:

I'll try them when the archive doesn't work.

Thank you very much for your informative answer.:smile:
 
Last edited by a moderator:

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K