# Re: Array formulas, piecewise functions

• From: Oliver Burnett-Hall <olly burnett-hall co uk>
• To: gnumeric-list gnome org
• Subject: Re: Array formulas, piecewise functions
• Date: Wed, 14 Sep 2005 18:43:59 +0100

```Stephen R Laniel wrote:
```
```1) I'm familiar with array formulas from Excel, such that
one can do formulas like

=sum(if(and(\$G\$2:\$G\$30000>=H2,\$G\$2:\$G\$30000<H3),1,0))
```
```
[...]

```
```It shares a lot of similarities, apparently, with Excel's
array formulas, but it's not working for me. How do I have
to change the Excel formula to make it work in Gnumeric?
```
```
=SUM((\$G\$2:\$G\$30000>=H2)*(\$G\$2:\$G\$30000<H3))

This works in Excel too.

```
```2) I have a piecewise function defined as follows:

f(t) = (1/2)t^2         , 0 < t < 1
= -(t^2 - 3t + 3/2), 1 < t < 2
= (1/2)(3-t)^2     , 2 < t < 3
= 0                  elsewhere

In Excel, assuming t was in column A, I'd do something like
so:

=if(and(0<a1,a1<1),.5*a1^2,if(and(1<a1,a1<2),-(a1^2-3*a1+3/2),...))

It's a mess, but that's what I'd do.

I can't get that to work in Gnumeric; it's returning FALSE
or TRUE when it should be returning a value.
```
```
```
This looks okay. If you're getting TRUE or FALSE then I guess you're missing some arguments to one of the IF functions - double-check them to make sure all of them have three arguments (test, if-true, if-false).
```
If you can't see anything wrong, post the complete function here.

HTH,

- olly

```