| Paste number 38391: | problem in storing values is array (created with make_array) |
| Pasted by: | trebor_home |
| When: | 2 years, 3 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+TMF |
| Channel: | #maxima |
| Paste contents: |
/*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 arry. 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)}This paste has no annotations.