Re: A question on Newton's Method



On Sun, 3 Apr 2005 12:31:41 -0600, James Van Buskirk wrote:
> "Jon Harrop" <usenet@xxxxxxxxxxxxxx> wrote in message
> news:42500867$0$63445$ed2e19e4@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

>> What is Lisp-like about Mathematica and OCaml?

> They are equally incomprehensible.

>> Yes it does:

>> In[1]:= f[x_] = x^3 - x - 1

>> Out[1]= -1 - x + x^3

>> In[2]:= D[f[x], x]

>> Out[2]= -1 + 3 x^2

> No, the right context is:

> f[x_] := x^3-x-1
> fp[x_] := D[f[x],x]
> Plot[fp,{x,-1,2}]

> Which, unless they changed Mathematica recently, doesn't
> do anything useful.

There are two things wrong there. First, if you try Plot[f,{x,-1,2}],
you will find that it doesn't do anything useful, either. The first
message is

Plot::plnr : f is not a machine-size real number at x = -2.

This should be a clue that what you really wanted to do was
Plot[f[x],{x,-1,2}], since f[x] is a number but f is a function.
The Plot function expects something that evaluates to a number as its first
argument.

Second, you could have plotted the derivative by using Plot[f'[x],{x,-2,1}].
If you insist on using the D[f[x],x] syntax, then you need to use
delayed assignment (:=) instead of immediate assignment (=). The
following works:

In[1]:= f[x_] := x^3-x-1

In[2]:= fp[x_] = D[f[x],x]

2
Out[2]= -1 + 3 x


Then you could have plotted using D[fp[x],{x,-2,1}].

--
Dave Seaman dseaman@xxxxxxxxxx
Rosen Center for Advanced Computing YONG 517
http://www-rcd.cc.purdue.edu/~dseaman/ Phone: (765) 496-8218
.



Relevant Pages

  • 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: Very poor Lisp performance / about Mathematica
    ... >> You cannot predict what such an OCaml program will do. ... Not using them is considered an abuse of the language. ... I wouldn't apply any of that theory to Mathematica directly. ...
    (comp.lang.lisp)
  • Re: K interpreter
    ... Comparing the fastest k implementation to the slowest OCaml implementation, ... I don't believe it is possible to design a set of adverbs that allow all ... in k style (or Mathematica). ... it would take me a lot longer to optimise the Mathematica than it ...
    (comp.lang.functional)
  • Re: CL failure stories?
    ... Mathematica version also does this. ... That's vastly better than the original Lisp code! ... In SML and OCaml you would write eval yourself. ... - fun eval state = fn ...
    (comp.lang.lisp)
  • Thats not Ridiculous Syntax... THIS is Ridiculous Syntax! (And REALLY expensive software!)
    ... excerpts from the Mathematica manual. ... different places in memory. ... you will recognize Mathematica pure functions as being like ... called a "context mark" in Mathematica. ...
    (comp.lang.lisp)

Loading