Tutorials covering iteration, lists and debugging?
Subject: Tutorials covering iteration, lists and debugging?
From: Robert Dodier
Date: Wed, 24 Jul 2013 16:41:05 +0000 (UTC)
On 2013-07-24, Richard Owlett <rowlett at cloud85.net> wrote:
> (%i1) numer: true$
> dTHETA: (2 * %PI/10)$
> THETA: 0$
> table: makelist()$
> for j: 0 step (dTHETA) thru ( 2 * %PI) do
> ( table: append(table,[sin(THETA)]),
> THETA: THETA + dTHETA);
As pointed out elsewhere, should be %pi instead of %PI.
Maxima prefers exact numbers (integers and rationals) to inexact
(floats). In particular, various trigonometric simplifications can only
be applied to exact values. So my advice is to preserve exact values as
much as possible, e.g.:
(%i21) numer : false $
(%i22) makelist (sin (i/n*2*%pi), i, 0, n), n=10;
(%o22) [0,sin(%pi/5),sin(2*%pi/5),sin(3*%pi/5),sin(4*%pi/5),0,sin(6*%pi/5),
sin(7*%pi/5),sin(8*%pi/5),sin(9*%pi/5),0]
(%i23) %, numer;
(%o23) [0,.5877852522924731,.9510565162951535,.9510565162951536,
.5877852522924732,0,-0.587785252292473,-.9510565162951535,
-.9510565162951536,-.5877852522924734,0]
HTH
Robert Dodier