Maxima vs Axiom



On Sat, Nov 26, 2011 at 12:32, Daniel Carrera <dcarrera at gmail.com> wrote:
Re

> * I am not crazy about the way either Maxima or Axiom do functions. I
> think that implementing the Newton-Raphson method should work more or less
> like this:
>
> f(x) := x^2 + x - 2
> df(x):= D( f(x),x )
> nr(x):= x - f(x)/df(x)
>
> nr(0.7)
> for i = 1,10
>    nr(%)
> end


You can do this with only trivial, superficial syntactic changes in Maxima:

define( f(x) , x^2+x-2 )$
define( df(x) , diff(f(x),x) )$
define( nr(x), x-f(x)/df(x) )$
( t: nr(.7),
  for i thru 10 do t:nr(t) )$


This is not the way I'd recommend doing things, but you can certainly do it
this way.

If you prefer an infix syntax for definition, you can easily define it like
this:

infix("%:%",20,20)$
(a %:% b) := define(ev(a),b);


and then write:

f(x) %:% x^2+x-2 $
df(x) %:% diff(f(x),x) $
nr(x) %:% x-f(x)/df(x) $


Not sure what that gains you.

But again, I DO NOT recommend working like this....


           -s