# Object on a SlopeΒΆ

This is an example which will show the usage of `paramcomparison.readers.UserFunctionReader`

.

Let’s say we have a simple physics problem: we have an object which is put on a slope. What is the time it takes for the object to slide down to the ground, given the following 4 parameters:

- the angle of the slope \(\theta\),
- the coefficient of friction \(\mu\),
- the initial height of the object \(h\),
- the gravitational acceleration \(g\) (we may not be on the Earth).

This is a rather simple problem, and the time can be computed using the following formula:

If \(t\) is an imaginary number (in other words, the result in the square root is negative), then it means the object would not slide down.

Here, we will use ParamComparison to generate tables to display the relation of the parameters with the actual time it takes to fall down.

We create a python script to generate the tables using
`paramcomparison.readers.UserFunctionReader`

:

```
#!/bin/env python
import paramcomparison
from paramcomparison.writers import RstWriter
from paramcomparison.readers import UserFunctionReader
# the function which computes the time for the object to fall to the ground
def compute_sliding_time(params, data):
from math import sqrt, sin, cos
theta = float(params['theta'])
mu = float(params['mu'])
g = float(params['g'])
h = float(params['h'])
tmp = 2 * h / (g * sin(theta) * (sin(theta) - mu * cos(theta)))
if tmp < 0: # the object does not slide
return 'never'
# limit the number of digits to 2
return '{0:.2f}'.format(sqrt(tmp))
param_space = {'theta': ('0.52', '1.05'), 'mu': ('0.1', '0.3', '1.0'),
'g':('1.6', '3.7', '9.8'), 'h': ('1', '2', '3')}
pc = paramcomparison.ParamComparison(param_space,
UserFunctionReader(compute_sliding_time, None))
pc.generate_pages('output', RstWriter(), 'theta', 'mu')
```

You can download `the script`

and view *the output of this example*.

Here we generated two pages. Each of the pages lists tables which include all the possible
combinations, but the two pages order the tables in different ways: *the page g*
fixes \(h\) and compare the effect of changing \(g\) within each block separated by
horizontal lines, while *the page h* fixes \(g\) and compare the effect of
changing \(h\) within each block.

This example may not be very typical though – paramcomparison is probably more useful when it comes to experimental data.