POV-Ray : Newsgroups : povray.text.tutorials : Summing over indices of an array : Re: Summing over indices of an array Server Time 2 Mar 2024 11:36:45 EST (-0500)
 Re: Summing over indices of an array
 From: moocow Date: 2 Jan 2006 20:05:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.43b9cd3b4b45696074508c90%40news.povray.org",
"headline": "Re: Summing over indices of an array",
"dateCreated": "2006-01-03T01:05:00+00:00",
"datePublished": "2006-01-03T01:05:00+00:00",
"author": {
"@type": "Person",
"name": "moocow"
}
}
Christoph Hormann <chr### [at] gmxde> wrote:
> Mike Williams wrote:
> >
> > I think you have to use a loop:
> >
>
> Bah, you surely don't have to:
>
>    #if (i>0)
>    #else
>      #local R=elem[i];
>    #end
>    R
> #end
>
>
> ;-)
>
> Christoph
>
> --
> POV-Ray tutorials, include files, Sim-POV,
> HCR-Edit and more: http://www.tu-bs.de/~y0013390/
> Last updated 23 Sep. 2004 _____.//^>_*_<^/.______

What if I want to define a function as a sum of other functions?

#declare X = array[N]
//set X's

#declare f = function{ sum(i, 0, N-1, pow(.5, pow( vlength(<x,y,z> - X[i]),
2))) }

I can't think of how to make that work.

Also, why these restrictions? Why can't I sum outside a function or use
arrays inside? Why can't I do:
#define f1 = function { f1(x,y,z) + g(x,y,z) }
?
```