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

In summary, the conversation discussed a problem with defining derivatives of functions in Maxima and how to solve it by localizing the derivative variable and using the construct ''(diff(F(x),x)). Suggestions for further help were also provided.
  • #1
HotMintea
43
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
  • #2
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.
 
  • #3
Are we supposed to know the syntax for 'Maxima'? Is it a very common software package?
 
  • #4
@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:
  • #5
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:

1. What is the definition of a derivative function in Maxima?

The derivative function in Maxima is a new function that represents the rate of change of another function at a specific point. It is defined as the limit of the difference quotient as the interval between two points approaches zero.

2. How is the derivative function calculated in Maxima?

In Maxima, the derivative function can be calculated using the 'diff' command. This command takes the derivative of a given function with respect to a specified variable. For example, 'diff(f(x), x)' would calculate the derivative of the function f(x) with respect to the variable x.

3. Can the derivative function in Maxima be graphed?

Yes, the derivative function in Maxima can be graphed using the 'plot2d' command. This command allows you to plot multiple functions on the same graph, making it easy to compare the original function and its derivative.

4. What is the significance of the derivative function in Maxima?

The derivative function in Maxima is significant because it helps us understand the behavior of a function at a specific point. It tells us the slope of the tangent line at that point, which can provide valuable information about the rate of change and the behavior of the function.

5. Are there any limitations to using the derivative function in Maxima?

One limitation of using the derivative function in Maxima is that it may not always be able to find the exact derivative of a given function. This can happen when the function is too complex or involves special functions that Maxima does not recognize. In these cases, it may be necessary to manually calculate the derivative or use a different software tool.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
Replies
4
Views
353
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
2K
  • Calculus
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
406
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top