Hello,
In the thread: >https://www.novabbs.com/devel/article-flat.php?group=comp.lang.forth&id=16944&first=1&last=25#start
Paul Robin posted:
For example, sin (sine) is a function, whose input is a real and
whose
output is another real. And "derivative" (d/dx) is a function whose
input is a function, and whose output is another function. So you
get
that d/dx (sin) = cos, or some numerical approximation of same. In
Python or Haskell, this is easy, e.g.:
h = 0.0001
d_over_dx f = g where { g x = (f(x+h) - f(x)) / h }
dsin = d_over_dx sin
print (dsin 0.5) -- prints 0.8775585891507287
print (cos 0.5) -- prints 0.8775825618903728
Pretty close approximation. In Forth it is a bit messier because you
want a signature like
: d/dx ( xt -- xt ) .... ;
and you may have to do some advanced or non-portable things to create
new xt's on the fly like that.
Why not do it directly like this:
: d/dx ( xt -- )
create ,
does> @ dup ( f: x -- y) fdup 1e-4 f+ execute fswap 1e-4 f-
execute f- 0.5e4 f* ;
and the dervative of any function can be obtained directly like this:
' func() d/dx der_func()
for example: (in gforth)
' fsin d/dx der_fsin ok
0.5e fcos f. 0.877582561890373 ok
0.5e der_fsin f. 0.877582560427637 ok
that d/dx (sin) = cos, or some numerical approximation of same. In
Python or Haskell, this is easy, e.g.:
h = 0.0001...
d_over_dx f = g where { g x = (f(x+h) - f(x)) / h }
I have a question concerning your derivative implementation (the link
you've given):
in the word derivative, we find:
dx1 F@ F0= dx2 F@ F0= or
IF 1 unloop EXIT THEN
why you use or in the condition? why not and?
I think you implemented:
the derivative at (x1, f(x1)) as
Hi again,
But in that case, one still can calculate the derivative d/dx (f(x1)) = (f(x2)-f(x0))/(x2-x0) where (x0,f(x0)), (x1, f(x1)) and (x2, f(x2)) are
three consecutive
points with:
- x1 = x0 and f(x1) != f(x0) and x2 != x1.
or - x2 = x1 and f(x2) != f(x1) and x1 != x0.
The problem is when x2 = x1 = x0, and that's why I asked why not "and"
in place of "or".
Ah, I see.
Thanks for the reply.
On 5/25/24 15:32, Ahmed wrote:
Ah, I see.
Thanks for the reply.
My derivative routine is basic. For experimental data, it assumes you
have done whatever preprocessing on the raw data to provide a reasonably >smooth approximation of an analytic function to it.
In measurements, one is rarely dealing with data which, in raw form, is
an analytic function.
--
Krishna
In article <v2v762$3d4ji$1@dont-email.me>,
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
On 5/25/24 15:32, Ahmed wrote:
Ah, I see.
Thanks for the reply.
My derivative routine is basic. For experimental data, it assumes you
have done whatever preprocessing on the raw data to provide a reasonably
smooth approximation of an analytic function to it.
In measurements, one is rarely dealing with data which, in raw form, is
an analytic function.
An analytic function is defined in an infinitly many immeasurable
points where only Descartes and Cantor pretend to know the properties off. Seriously?
At most an analytic function is a pretend thing, not a property of real
data, not even "rarely".
On 5/27/24 02:05, albert@spenarnc.xs4all.nl wrote:
In article <v2v762$3d4ji$1@dont-email.me>,
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
On 5/25/24 15:32, Ahmed wrote:
Ah, I see.
Thanks for the reply.
My derivative routine is basic. For experimental data, it assumes you
have done whatever preprocessing on the raw data to provide a reasonably >>> smooth approximation of an analytic function to it.
In measurements, one is rarely dealing with data which, in raw form, is
an analytic function.
An analytic function is defined in an infinitly many immeasurable
points where only Descartes and Cantor pretend to know the properties off. >> Seriously?
At most an analytic function is a pretend thing, not a property of real
data, not even "rarely".
Good grief. We shouldn't even be talking about numerical differentiation >then.
--
Krishna
Hi,
I think Mr K. M. meant "analytic formula fitting the acquired (measured) >data".
And analytic functions are a class of functions over the complexe plane
(C) with some properties that give them certain characteristics
(derivation for example).
See the link
https://en.wikipedia.org/wiki/Analytic_function
Best regards.--
melahi_ahmed@yahoo.fr (Ahmed) writes:
Hello,
In the thread: >>https://www.novabbs.com/devel/article-flat.php?group=comp.lang.forth&id=16944&first=1&last=25#start
Paul Robin posted:
For example, sin (sine) is a function, whose input is a real and
whose
output is another real. And "derivative" (d/dx) is a function whose
input is a function, and whose output is another function. So you
get
that d/dx (sin) = cos, or some numerical approximation of same. In
Python or Haskell, this is easy, e.g.:
h = 0.0001
d_over_dx f = g where { g x = (f(x+h) - f(x)) / h }
dsin = d_over_dx sin
print (dsin 0.5) -- prints 0.8775585891507287
print (cos 0.5) -- prints 0.8775825618903728
: d/dx ( xt -- )
create ,
does> @ dup ( f: x -- y) fdup 1e-4 f+ execute fswap 1e-4 f-
execute f- 0.5e4 f* ;
' fsin d/dx fdsin
0.0001e fvalue h
: d/dx1 ( r1 xt -- r2 )
fdup h f+ dup execute fswap execute f- h f/ ;
: d/dx ( xt1 -- xt2 )
r :noname ( r1 -- r2 ) r> postpone literal postpone d/dx1 postpone ; ;
0.5e ' fsin d/dx execute f. \ prints 0.877558589150729
Even signals disturbed by noise and smoothed by splines
often show considerable deviations in their first derivative.
This can even make them unusable. Simple bandpass filters,
e.g. classic Butterworth, are often better. Finding the right
frequency bands is usually a question of empirical experience.
On 5/26/24 08:50, minforth wrote:
Even signals disturbed by noise and smoothed by splines
often show considerable deviations in their first derivative.
This can even make them unusable. Simple bandpass filters,
e.g. classic Butterworth, are often better. Finding the right
frequency bands is usually a question of empirical experience.
I'm wary of using filters in connection with computing derivatives.
Filters will exhibit latency and therefore alter some properties of a
signal.
One such case might be a repetitive signal consisting of a
short-duration pulse followed by a long-duration pulse. If we want to
obtain a measure of the peak to peak time interval between the short
and
long pulse within a cycle, the distortion of the waveform by the filter
has to be considered.
Alternatively, if a trigger pulse is available to mark the start of the
cycle, the repetitive signal can be averaged until the noise is low
enough to use a derivative to obtaining the zero crossings. Curve
fitting is generally a better technique though, when a model function
exists.
In article <1be75ceb4dfcfb241237191acda06020@www.novabbs.com>,
ahmed <melahi_ahmed@yahoo.fr> wrote:
Hi,
I think Mr K. M. meant "analytic formula fitting the acquired (measured) >>data".
And analytic functions are a class of functions over the complexe plane
(C) with some properties that give them certain characteristics
(derivation for example).
See the link
https://en.wikipedia.org/wiki/Analytic_function
An analytic function has the properties that if you know a
tiny environment -- mathematically speaking --
you can calculate all derivatives and use these in a series
formula to calculate the function anywere.
So If you know the orbit of the earth for the next 10 mS
you could calculate the position to all eternity
(forgetting about 3 body problems and chaos theory.)
This is all nice and dandy for the Rieman Zeta function but not
for this situation.
(I have a degree a theoretical physics. I'm not worth a
dime in physics, but this mathematics subject I was quite
good at.)
Best regards.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 502 |
Nodes: | 16 (2 / 14) |
Uptime: | 213:50:32 |
Calls: | 9,878 |
Calls today: | 6 |
Files: | 13,791 |
Messages: | 6,205,406 |