# [PD] numerical constraints (scaling)

Sat Aug 1 18:43:56 CEST 2009

```Hi JBeez,

We could interpret this in two ways. A hard constraint is applied by
using [moses] [max], [min] or [clip] so that numbers outside the
desired bounds are simply discarded, or clamped to the boundry.
Look that one up in the help files if it's what you want.

On the other hand, I think you really mean to rescale the numbers
so that all of them fit between your new bounds.

Changing a range requires a linear scale function. There
is one called [scale].

a good idea to understand the simple principle of changing the
slope and origin of a line.

If your original bounds are 800 and 19000 then the magnitude
of the range, the interval, is 19000 - 800 = 18200

The origin of the interval is 800, which is the lowest
number you can have.

The first thing to do is 'reset the origin' so that all
your numbers have a lowest value starting at zero, so
to do that subtract 800.

Then scale the line to cover the magnitude of your new interval,
which is 800 - 400 = 400

To map 18200 to 400 divide them to get 400/18200 = 0.021987

Now scale the numbers by that factor

the lowest value of the new range which is 400

So the complete scale function is now

((x - 800) * 0.021987) + 400

(see attached patch)

a.

On Sat, 1 Aug 2009 15:32:06 +0100
J bz <jbeezez at googlemail.com> wrote:

> Dear all a y'all,
>
> I have a list of 25 numbers between 800-19000 that I'm calling randomly'ish.
>
> I want to add some constraints to those numbers:
> so for example, I have the number 6569 and by the use of either simple x2
> multiplication or dividing I want to shoehorn it into the ranges of
> 11000-18000 but also 400-800 at the same time.
>
> THe ranges are set but the numbers aren't.  So say sometimes the range
> 2400-4700 may get a number that is less than the range like 912 and
> sometimes it will get a number over the range like 13264, so I need a way of
> Pd recognising whether the number requires multiplication or dividing.
>
> How can I do this?
>
> Bests,
>
> Jbz
>

--
Use the source
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scaling.pd
Type: application/octet-stream
Size: 713 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20090801/6f86e606/attachment.obj>
```