program that finds antiderivative

This is a discussion on program that finds antiderivative within the C++ Programming forums, part of the General Programming Boards category; Has any one here ever written a program that finds the derivative or anti derivative? Because I'm trying to write ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    18

    program that finds antiderivative

    Has any one here ever written a program that finds the derivative or anti derivative?
    Because I'm trying to write a program that finds the derivative or antiderivative but I don't know where to start. I dont know how I would allow the user to enter in their f(x) and then take that and find the derivative or antiderivative? Any tips or tricks would be appreciated thanks

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I believe, might be wrong, that in order to do that you have to do it the way you would do it with a pen and paper.
    You have to parse an expression, make a tree with all the variables, then apply some rules on them. Lets say you have one variable, x. And only +, * and ^
    Example:
    f(x) = 2*x + x^2
    Node0 (Root)
    var1 = Node1
    var2 = Node2
    operator = +

    Node1
    var1 = 2
    var2 = x
    operator = *

    Node1
    var1 = x
    var2 = 2
    operator = ^

    Then you evaluate first Node1 and Node2. You will get x from Node1 and 2*x from Node2. Then you apply the + operator from Node0 and get 2 + 2*x, which is the result.
    Now, every node will be a struct, which is up to you how to implement. But you can use the above as the basic idea.
    If you have (,) note that things get more complicated, so I suggest starting simple.
    If the above isn't clear I can elaborate a bit more.

    Note that if you had numbers, not variables, like df(4)/dx then maybe there are some arithmetic algorithms that come close (really close) to the real result. Those are used generally to calculate a result. Computers don't do this as humans.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Derivative yes, anti-derivative no.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Just to clarify that the antiderivative would be solved in almost an identical way. The only difference is that if you have, for example, f(x) = x^2 you will create two functions:
    1) derivative(f) = 2*x
    2) antiDerivative(f) = (3/2) * x^3

    So if you find how to do one, you can easily do the other

  5. #5
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    if you need to evaluate an integral, then it's easy. if you need to provide a symbolic answer, then you're in for a world of pain.

    edit: to answer your other question, yes there is software out there that does that:

    http://www.maplesoft.com/

    http://www.wolfram.com/

  6. #6
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    Quote Originally Posted by C_ntua View Post
    Just to clarify that the antiderivative would be solved in almost an identical way. The only difference is that if you have, for example, f(x) = x^2 you will create two functions:
    1) derivative(f) = 2*x
    2) antiDerivative(f) = (3/2) * x^3

    So if you find how to do one, you can easily do the other
    try f = e^(-x^2)

  7. #7
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Graphmatica too

  8. #8
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    The approximations of either are easily handled by a computer. However, as someone else suggested, finding the symbolic answer is not easy (it's nearly impossible for most humans to program that).

    Computers are akin to finding the approximations of either derivatives(using Newton's method comes to mind) or anti-derivatives.

    Coming up with a symbolic answer is a lot tougher. Think if you had to program the logic to come up with a symbolic answer for an integral that involved trig-integration. That would be a rather daunting task!

    Generating a symbolic answer for derivatives is just as difficult if you consider implicit-differentiation and any other type of derivative that doesn't involve simple polynomials (i.e., one's that don't intuitively conform to x^2dx = 2x^x-1).

    However, if you're looking only to use your program on simple polynomials, I think you could do that with little effort.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  9. #9
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    About your question on how to allow the user to enter the polynomial, that's easy and there's a number of ways to do it.

    In school I once had to program that did different operations on polynomials and user input was as easy as letting the user enter terms in this fashion:
    Code:
    [Q]-quit [E]-enter term
    e
    Enter order: 2
    Enter coefficient: 3
    q
    would mean the user entered 3x^2. You can store those terms in a container (list,vector,etc), and overload the "<" operator( checking orders first, then coefficients if necessary, and if orders are equal, add the coefficients), call sort on the container, and whola! you have the standard form for your polynomial.

    Implementing the derivative/anit-derivative, then running it on the container is a snap!
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  10. #10
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    newton's method is a root-finding algorithm that requires the derivative as part of the equation...

    can it be used to solve for derivatives? seems like there's an 'incompleteness' problem there.

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by dudeomanodude View Post
    The approximations of either are easily handled by a computer. However, as someone else suggested, finding the symbolic answer is not easy (it's nearly impossible for most humans to program that).
    And yet my TI-89 does it.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Thantos View Post
    And yet my TI-89 does it.
    So that means TI found a couple of the humans that can. And much like the dog that sings showtunes, it's not that the TI does it well (because it doesn't), it's that it does it at all.

  13. #13
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    The TI does it sure, but often what it spits out is not the answer you would expect nor does it look like what you would get by finding the answer with pen and paper.

    Nearly impossible for humans
    well, i'm sure they've got some mathematical geniuses at TI who came up with what they have, and at best, what they've come up with is certainly not perfect.

    I want a human to write a program that comes up with the symbolic answer to find the derivative/anti-derivative of anything, perfectly... my bet is that will never happen.

    about newton's method, perhaps i was thinking about a way to find the anti-derivative... not sure, but I do remember writing a program that found the approximations and it wasn't terribly difficult (can't remember if it was derivatives or anti now)
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by dudeomanodude View Post
    The TI does it sure, but often what it spits out is not the answer you would expect nor does it look like what you would get by finding the answer with pen and paper.

    well, i'm sure they've got some mathematical geniuses at TI who came up with what they have, and at best, what they've come up with is certainly not perfect.

    I want a human to write a program that comes up with the symbolic answer to find the derivative/anti-derivative of anything, perfectly... my bet is that will never happen.

    about newton's method, perhaps i was thinking about a way to find the anti-derivative... not sure, but I do remember writing a program that found the approximations and it wasn't terribly difficult (can't remember if it was derivatives or anti now)
    I'm pretty sure it CAN be done for things that actually have defined integrations (anti-derivative), as there are fairly good rules for these things. However, in many cases, the integral calculation is not defined.

    However, integral calculus is a complicated part of math, and it does contain A LOT of rules that are not particularly easy to describe to a computer. Here's one example:
    http://en.wikipedia.org/wiki/Trigonometric_substitution

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by m37h0d View Post
    try f = e^(-x^2)
    Well, yeah that is kind of hard. The result is 1/2*pi*erf(x) according to this tool

    Antiderivatives are hard to solve, because not all can be solved. There are a lot of methologies also, which really makes it difficult. You will require a lot of math, which personally I don't know. But it is possible.
    Alternatively, you create a program that connects to a site like the above, gets the result and prints it :P

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21