Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Sep 4, 2011 #1
    For example,

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

    didn't seem to work, since


    returned an error.

    Any help would be appreciated.
  2. jcsd
  3. Sep 4, 2011 #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.

    Ax(x):=diff(A(x), x,1);


    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.
  4. Sep 4, 2011 #3
    Are we supposed to know the syntax for 'Maxima'? Is it a very common software package?
  5. Sep 4, 2011 #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 [Broken]

    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: May 5, 2017
  6. Sep 5, 2011 #5
    Thanks for the explanation. Now I understand why.

    It definitely worked.

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

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

    Thank you very much for your informative answer.:smile:
    Last edited by a moderator: May 5, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook