www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/11/06:14:32

Xref: news2.mv.net comp.os.msdos.djgpp:945
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Integrals/Derivatives in C
Message-ID: <1996Feb6.151808.2353@rcwusr.bp.com>
From: wooledgj AT techsrv1 DOT clv DOT ous DOT bp DOT com (Greg Wooledge x5932)
Date: 6 Feb 96 15:18:07 -0400
Reply-To: wooledge AT kellnet DOT com
References: <00009419+00000ad1 AT msn DOT com>
Nntp-Posting-Host: 164.63.144.17
Lines: 29
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

ohd AT msn DOT com (David Oh) writes:

>	I was wondering if anyone out there can help me out with a simple C 
>code fragment to find the (numeric & symbolic) derivative or integral 
>of a function.

This was part of a program I wrote to get a master's degree.  I don't
think it can be done in a "simple C code fragment", unless you have an
unusual notion of "simple".

I don't know where that code is right now.  It's probably on a diskette
somewhere.  If I happen to find it, I'll send it your way.  (It's not
terribly big.)

If the function is to be typed in (or read from a file, or whatever), then
you need some sort of parser.  That's non-trivial at best.  To take the
derivative, you can apply recursive rules to the parse tree, but you'll
probably want to simplify it afterward.  Numerical integration isn't too
hard -- just look up a good algorithm in a numerical methods book.  You'll
need to be able to evaluate the function at arbitrary values in the
domain, which again can be done without too much work after you've built
the parse tree.

If the function is to be hard-coded in the program, as a regular C
function, then numerical integration becomes nearly trivial.  The compiler
parses everything for you, and you just need a loop and some arithmetic.

I never touched symbolic integration.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019