teaching code for newton2



Wolfgang, for better or worse Maxima doesn't handle vectors and
matrices as you might expect. With that in mind ...

> numer  : true;
> f(a,x) := matrix([Sin(a*x)],[a-2]);

Maxima sine function = sin (not Sin). Likewise cos, exp, log, etc.

> J(a,x) : =matrix(''diff(f(a,x),a),''diff(f(a,x),x));

The quote-quote needs to be applied to all of diff(...) (not just the
diff symbol itself). So you want matrix(''(diff(...)), ''(diff(...)))
or maybe ''(matrix(diff(...), diff(...))).

> /* What is wrong with the following line? */
> [a,x]: [1.5,1.5];

Multiple assignment is a new feature in Maxima.
It will be in the next (5.12) release.

> /*
>   How to manage the following line?
>   [a,x] is type list I think, the product is type matrix.
>   So I have to coerce it someway - but how?
> */
> for i:1 thru 100 do ( [a,x] : [a,x] + J(a,x)^^(-1).(-f(a,x)) );

Probably better to manage ax as one variable (instead of
separate a and x variables).

Here's an attempted rewrite.

numer  : true;
f(ax) := [sin(ax[1,1]*ax[2,1]), ax[1,1] - 2];
J(ax) := ''(matrix (diff (f(ax), ax[1,1]), diff (f(ax), ax[2,1])));
ax : matrix ([1.5], [1.5]);
for i:1 thru 100 do ax : ax + J(ax)^^(-1).(- f(ax));
ax;

I get ax = matrix([2.0],[-0.059384277322756]).
It's a little disconcerting that the result differs after just a few
decimal places ... probably a consequence of the repeated
conversions float-to-rational and vv.

HTH
Robert Dodier