POV-Ray : Newsgroups : povray.newusers : sum over array of functions : sum over array of functions Server Time
2 Jun 2024 15:09:11 EDT (-0400)
  sum over array of functions  
From: Norman
Date: 18 Feb 2013 09:40:01
Message: <web.51223ca9839c96992224e72f0@news.povray.org>
Hello!

I would like to create a function (used inthe definition of an isosurface) which
itself consists of a sum of functions. The number of summands in this sum
function should be declarable.

How this can be done for merges, intersections or differences via min() and
max(), respectively, was pointed out in a very old thread here:
http://news.povray.org/povray.newusers/thread/%3C3d69631b@news.povray.org%3E/
and is demonstrated in iso_cgs.inc as mentioned in that thread.

However, this seems not to work with sum().

If I do


#declare f_test = array [2]{
  function (x) { (x)*1 },
  function (x) { (x)*2 }};

#declare f_summe = function(x) {sum(i,0,1,f_test[i](x))};


I get a "Parse Error: Expected 'numeric expression', undeclared identifier 'i'
found instead". Is there any workaround to do the job?

Additonally, I would like to mention that it is not possible to use
dimension_size(f_test,1)-1
as final value expression of the sum, like in

#declare f_summe = function(x)
{sum(i,0,dimension_size(f_test,1)-1,f_test[i](x))};

yielding a "Parse Error: Expected 'operand', array identifier found instead. Is
this a bug, feature or am I doing something wrong?
Anyway, I can work around this, but not the non-working sum above.

Help is greatly appreciated!


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.