global vars in function defined with block statement used for rk()



Hi,
count equals 1, because rk called f(x) only once, in order to get an 
expression (which in this case is "cos(x)+1") and then it used that 
expression (rather than the function f) to do all the iterations.
Regards,
Jaime


On 17-09-2013 22:05, Ether Jones wrote:
> Hello,
>
> Listed below is a simple mac script and the output from Maxima.
> Why is the value of the global variable "count" equal to 1 after the 
> rk integration?
> I would think the function would be called many times.
>
> I ask this because for the problem I am working on I need to define a 
> function with a block statement because I need state variables in the 
> function.  I couldn't find how to define local static variables in the 
> block statement, but the manual said that globals could be used.
>
>
> Maxima 5.27.0 http://maxima.sourceforge.net
> using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
> Distributed under the GNU Public License. See the file COPYING.
> Dedicated to the memory of William Schelter.
> The function bug_report() provides bug reporting information.
>
> (%i1)
> read and interpret file: #pK:/___workspace (primary)/block & rk.mac
>
> (%i2)                              kill(all)
> (%i1)                           load(dynamics)
> (%i2)            f(x) := block(count : 1 + count, 1 + cos(x))
>
> (%i3)                              count : 0
> (%o3)                                  0
>
> (%i4)                   rk(f(x), x, 0, [t, 0, 1, 0.1])
> (%o4) [[0, 0], [0.1, 0.19933719479999], [0.2, 0.39479088554581],
> [0.3, 0.58291320585305], [0.4, 0.76101220392991], [0.5, 
> 0.92729450156583],
> [0.6, 1.080838139697632], [0.7, 1.221450959001802], [0.8, 
> 1.349480845721376],
> [0.9, 1.465629133150566], [1.0, 1.570795255279214]]
>
> (%i5)                                count
> (%o5)                                  1
> (%i6)
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima