problems in storing values into an array made with make_array
Subject: problems in storing values into an array made with make_array
From: Robert Gloeckner
Date: Tue, 20 Mar 2007 17:56:20 +0100
Hello,
/*i would like to put results of a function into a file for later
gnuplotting it.
first step is to evaluate the function without quitting if an error
occurs this is done with "try1d" - the result is either a value or "?".
second step is to put all the values (or the "?") into an array. this
should be done with "testfunc1d". i need this step, because if i would
try to put the values directly into a file using with_stdout, then all
error messages appear in this file, too.
last step would be to put those values into a file.
i fail in doing second step.
below you can see the function definitions and a test run. as you can
see, maxima does not store the value inside the array i created via
make_array, it does store a lisp expression. how can i force evaluation?
*/
/**********************************************************/
try1D(func1D, x) := block([result],
result : ev( errcatch( func1D(x)), numer),
if( length(result) < 1) then( "?") else (first(result)));
testfunc1d(func, xmin, xmax, xstep) := block([
n : ev((xmax - xmin)/xstep, numer), x, result_array],
print( "n = ", n),
result_array : make_array( any, ?truncate( 2 * (n + 1))),
(for i: 0 thru n do (
x : xmin + xstep * i,
result_array[ 2 * i ] : x,
result_array[ 2 * i + 1] : ev(try1D(func, x)))),
result_array);
/**********************************************************/
(%i72) testfunc1d(sin, 2.0, 9.0, 2.0);
n = 3.5
(%o72) {Array: #(2.0 (($try1D SIMP) %SIN 2.0) 4.0 (($try1D SIMP) %SIN
4.0) 6.#
0
(($try1D SIMP) %SIN 6.0) 8.0 (($try1D SIMP) %SIN 8.0) NIL)}
thanks for any hint
Robert