Solution

There are certainly a lot of ways this could be done and the "solution" I give here could be expanded significantly if you so desire (or made more statistically rigourous and/or useful).  

When you want to make one function dependent on another function, there are different ways to do it.  Each of these has some advantages and disadvantages.  For this particular case, we are going to develop a one command function that does everything we want (i.e., you don't have to define your generating function in advance).  

First, let's define a function, perturbFunc, that takes your generating function, the name of your independent variable, plugs in a value for x, and then displaces that value by some (pseudo) random amount:

[Graphics:../Images/index_gr_118.gif]

Here, [Graphics:../Images/index_gr_119.gif] gives you a pseudo-random real between -pertCoef and +pertCoef.  Also, notice that I take the absolute value of everything to make sure nothing becomes negative (we could have skipped this if negative values are acceptable).  For certain cases, this might really screw up your data (if perturbCoef is too big compared to your function values, for example).

Let's try this out for a few different functions and values. The third argument to this function (perturbCoef) is a way to control the maximum amount the value will vary from the value of your function.

[Graphics:../Images/index_gr_120.gif]
[Graphics:../Images/index_gr_121.gif]
[Graphics:../Images/index_gr_122.gif]
[Graphics:../Images/index_gr_123.gif]
[Graphics:../Images/index_gr_124.gif]
[Graphics:../Images/index_gr_125.gif]
[Graphics:../Images/index_gr_126.gif]
[Graphics:../Images/index_gr_127.gif]

Now, we need to generate a table (or "list" in Mathematica-speak) of data and graph it along with your original function:

[Graphics:../Images/index_gr_128.gif]
[Graphics:../Images/index_gr_129.gif]
[Graphics:../Images/index_gr_130.gif]

We can plot this using ListPlot to see how it looks:

[Graphics:../Images/index_gr_131.gif]
[Graphics:../Images/index_gr_132.gif]

[Graphics:../Images/index_gr_133.gif]

[Graphics:../Images/index_gr_134.gif]

What about the original function?

[Graphics:../Images/index_gr_135.gif]

[Graphics:../Images/index_gr_136.gif]

[Graphics:../Images/index_gr_137.gif]

Now let's superimpose them:

[Graphics:../Images/index_gr_138.gif]

[Graphics:../Images/index_gr_139.gif]

[Graphics:../Images/index_gr_140.gif]

Okay, now it's time to put all this together into one big function that will take your input and return the list of data (along with a convenient plot) that you can then work with.  There are a few changes that need to be made, but we will try to keep them as similar to the steps above as possible.  Comments to explain what is going on are enclosed in the code (* like this *).  

Notice that the entire "program" definition is enclosed in a Module[...] command and statements are separated by semicolons.  The three variables listed at the start of the module [Graphics:../Images/index_gr_141.gif] are all "local" variables that we use inside our program; we won't use them again outside of the program, so by "declaring" them in the module like this, we make sure they don't cause us problems later (i.e., we don't have to Clear them).

[Graphics:../Images/index_gr_142.gif]

The following generates fake data for the function [Graphics:../Images/index_gr_143.gif] and generates 21 data points evenly spaced between [Graphics:../Images/index_gr_144.gif] and [Graphics:../Images/index_gr_145.gif].  It will randomly perturb the y values from their correct values by ±6:

[Graphics:../Images/index_gr_146.gif]

[Graphics:../Images/index_gr_147.gif]

[Graphics:../Images/index_gr_148.gif]

You can also give a name to the results for later manipulation:

[Graphics:../Images/index_gr_149.gif]

[Graphics:../Images/index_gr_150.gif]

[Graphics:../Images/index_gr_151.gif]

Let's list this last set of data in a nice table form:

[Graphics:../Images/index_gr_152.gif]
0.` 5.304472484335779`
0.4` 5.167693161478772`
0.8` 5.578265856811024`
1.2` 6.723526769064662`
1.6` 6.278407654323921`
2.` 6.880074176117458`
2.4` 7.731546435873465`
2.8` 7.368941439771484`
3.2` 8.109839450736276`
3.6` 8.35209004429857`
4.` 8.354361519798791`
4.4` 8.545803749541877`
4.8` 8.200751692430797`
5.2` 8.310942518911896`
5.6` 8.060515060987782`
6.` 8.989827420003445`
6.4` 8.263429126668276`
6.8` 8.46444717543727`
7.2` 9.127289347211315`
7.6` 8.788374976525565`
8.` 8.544862261953144`
8.4` 9.022278049742381`
8.8` 8.493957685947109`
9.2` 9.089928306487653`
9.6` 8.844688992339282`
10.` 8.967825327932513`
10.4` 8.471384514046608`
10.8` 9.306743725505008`
11.2` 8.841021739421576`
11.6` 8.653203393877305`
12.` 8.558023053037664`
12.4` 8.975702543214545`
12.8` 8.960093836551954`
13.2` 8.696082135796292`
13.6` 8.742993547164366`
14.` 9.094734168494814`
14.4` 8.533284899309031`
14.8` 9.253935771736007`
15.2` 8.633736225181439`
15.6` 9.127853144783876`
16.` 9.355125293530968`
16.4` 8.928939238813753`
16.8` 8.693000324772804`
17.2` 8.566980825878852`
17.6` 9.073365222855953`
18.` 9.200712128111082`
18.4` 8.519999126607217`
18.8` 8.821399567549337`
19.2` 8.593358054968816`
19.6` 8.615246829866898`
20.` 9.446343335558089`

Or, let's graph the data with the origin where it should be and bigger dots:

[Graphics:../Images/index_gr_153.gif]

[Graphics:../Images/index_gr_154.gif]

[Graphics:../Images/index_gr_155.gif]


Converted by Mathematica      April 26, 2002