Plot bi-variate function f(x, y) with Monte Carlo method

The Excel workbooks "Random Plot.xls" can be also usefull for studing didactical problems.

For example find the Max and Min of the following linear function

During the computing for plotting function, the algorithm find also an approximation for the absolute max-min of the function inside the domain box

Comparing with the exact solution (2/3, 2/3), we get the precision of about 1 % - 1.5 %

Exact / Approximate / Error / Error % / Points
x / y / x / y
min / 0.666667 / 0.666667 / 0.653989 / 0.659698 / 0.0145 / 1.5 % / 2077
max / 2 / 2 / 1.970444 / 1.994513 / 0.0301 / 1 % / 2077

Switching to the "Plot2D" chart, we can see the xy-plane view.

Min and Max points are also rapresented by two colored dot (yellow for Max and cyan for Min).

The domain box - xmin <= x <= xmax and ymin <= y <= ymax is rapresented by a grey rectangle

In order to increase the quality and precision, we can add points to the previous plot , simply clicking the "Plot 2D" buttom. Another set of random point (about 2500 each time) is added to the plot. After two or three time, we have about 8000 points and the plot appears as the following:

As we can see the look is quite better but what about the precision?

Exact / Approximate / Error / Error % / Points
x / y / x / y
min / 0.666667 / 0.666667 / 0.6660539 / 0.672821 / 0.006185 / 0.7 % / 8221
max / 2 / 2 / 1.970444 / 1.994513 / 0.030060 / 1 % / 8221

Unfortunately, the precision increase very lower with points. In our example dispite of a 8000 number points, precision is quite the same of one with about 2000 points. This is characteristic of this method;

Precision can increase only if we reduce the area of analysis. Example, to refine the precision of max point we set the followin domain box: xmin= 1.8, xmax=2, ymin=1.8, ymax=2 and plot another set of points

You will note that the domain box is resized around the Max Point (yellow dot) indicating that the next set of random points will be generate in this area.

Click the "Plot 2D" buttom

With about 2000 points added we get for the Max Point

Exact / Approximate / Error / Error %
x / y / x / y
max / 2 / 2 / 1.998819 / 1.9991326 / 0.001465 / 0.1%

As we can see the precision of the Max Point has increased much more

Youn can observe that the points density at the upper right corner is also increased

We can reapeat this process for the Min Point; set xmin= 0.56, xmax= 0.76, ymin= 0.56, ymax= 0.76

we get the following results:

Exact / Approximate / Error / Error %
x / y / x / y
min / 0.6666667 / 0.6666667 / 0.6674248 / 0.6663483 / 0.000822 / 0.1%

The plot appears now as the following

Constrains

We repeat the previous exercise adding the constrain

The domain is changed from the previous one (rectangular domain)

We can plot both the area domain and the constrain following this process:

First of all we write the formulas constrains into the domain cells, starting from top to bottom. We can insert up to 9 different constrains In this example we have to add only one constrain, so we write in the first cell C15 the formula

Clear the prevous plot 2D. This reset also the Max- Min Table

Click the "Plot Domain area" bottom for drawing the Domain Area

Select the contrain cell C15 and click the "Plot" buttom into the "Domain Selected" Box. This drows only the constrain

In presence of many constrain we can draw all constrain graph by the "Plot Domain Border"

The Plot2D chart look like this following:

As usually the plot density can be regulated adding several points set

As we have checked the area domain, we go to the next step: plotting the f(x,y) into this domain

For that, clear all previus plot, clicking the "Clear Domain Area" . The Constrain plot can be left.

Now click two or three times the "Plot2D" buttom.

The Plot2D chart look like the following

As we can see, now the MaxPoint is moved near the point ( 0.5 ; 2), while the Min is unchanged.

From the table we get the approximate values with an error of about 0.8% that for this method is acceptable

Exact / Approximate / Error / Error % / Points
x / y / x / y
max / 0.5 / 2 / 0.5023886 / 1.9846177 / 0.015567 / 0.8% / 3710

We observe that this metod cannot found multiple absolute extreme. For example we know that there is also the Max Poin (2 ; 0.5) but this is ignored by this method.