Re: A question on Newton's Method



James Van Buskirk wrote:
> "Jon Harrop" <usenet@xxxxxxxxxxxxxx> wrote in message
> news:42503d87$0$42333$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> Really? Have you considered the Fortran equivalent of my numerical
> analysis
>> example? How about some other examples? Can you design a single example
>> of numerical analysis which is more comprehensible in Fortran?
>
> Please submit your equivalent of
>
> http://home.comcast.net/~kmbtib/conv2b.f90
>
> in the non-Fortran language of your choice!

That is a 2,199-line Fortran program. I believe the equivalent in
Mathematica is the built-in ListConvolve function which is 12 letters of
code. Of course, the Mathematica implementation is much more powerful as it
works for any "n".

An OCaml implementation would use FFTW and would probably be <100 lines and
also be more powerful than the Fortran you've given.

So the Fortran is several orders of magnitude more verbose than it need be.
That's hardly what I call a comprehensible example. Any other examples of
numerical analysis code which is actually simpler in Fortran?

>> Plot[f'[x], {x, -1, 2}]
>
> No, I don't want this! In ordinary everyday mathematical usage,
> you can define a new function to be the derivative of an old
> function. For example, psi(x) = (d/dx)(ln(Gamma(x))). We want
> to be able to do this in Mathematica; I don't want to keep
> referring to the original function (as in your f'[x] above.)

If you want to explicitly define a function, say "df", as the derivative of
"f" then just do it the obvious way instead of messing about with delayed
evaluation, the "D" function and unnecessarily-reused definitions:

df[x_] = f'[x]

or even:

df = f'

> So the original example should have been changed to:
>
>> > f[x_] := x^3-x-1
>> > fp[x_] := D[f[x],x]
>> > Plot[fp[x],{x,-1,2}]
>
> When you finally figure out how to make this work you will
> have an excellent example of the true horror of Mathematica!

No, your second attempt is also incorrect. Note that this isn't just
incorrect Mathematica code, it is actually incorrect mathematics - you've
reused "x".

If you write correct maths then it works perfectly:

fp[x_] = D[f[a],a] /. a -> x

Of course, it is better to do this the obvious way...

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.



Relevant Pages

  • Re: Verbose functional languages?
    ... Sometimes it is unavoidable to use Fortran. ... I used Mathematica a lot, ... We recently bought a Mac Mini and a SlideArch keyboard. ...
    (comp.lang.functional)
  • Re: A question on Newtons Method
    ... bug reports per day. ... there are arbitrary-precision integers and rationals (Num in OCaml, ... native format in Mathematica, and a major hassle in Fortran). ...
    (sci.math.num-analysis)
  • Re: dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... but not a single I/O operation on them. ... appear simpler for that rare I/O statement, but the fortran ... convention is simpler for those dozens or hundreds of lines of code ... years and Mathematica for about 15 years, ...
    (comp.lang.fortran)
  • Re: "Matlab to Scilab for Dummies" anywhere?
    ... Anyone know of an open-source clone of Mathematica? ... Back at the university we had to program in Fortran on punch ... will harp on)) is/are symbol manipulators. ... linear algebra problem or anything. ...
    (sci.electronics.design)