An Interesting Mathematical Function

I ran across an interesting function, apparently created by fellow named P. Charbonneau, in a couple of articles that deal with numeric optimization. See the image below. The function is:

f(x,y) = [16x(1-x)y(1-y)sin(9*pi*x)sin(9*pi*y)]^2

The function has one global maximum value at x = 0.5 and y = 0.5. Here’s how to graph the function using SciLab, a free program similar to the over-priced MatLab:

-->Z = (16 * (xx .* yy) .* (1 - xx) .* (1 - yy) .* sin(9*%pi*xx) .*
   sin(9*%pi*yy)) .^ 2;

(Note: original post has a missing ) in the code. Now corrected. See comments.)

Graphing the function is a little bit tricky; it took me a while to get my * operator (regular multiplication) and .* operator (value by value in a matrix multiplication) correct. And I had to remember to use Z’ (the transpose) instead of Z when calling the plot function. The function has a maximum value when x = y = 0.5. Because the function has 81 peaks, it’s a difficult function for many algorithms to optimize.

This entry was posted in Software Test Automation. Bookmark the permalink.

2 Responses to An Interesting Mathematical Function

  1. A parenthesis is missing here:
    Z = (16 * (xx .* yy) .* (1 – xx) .* (1 – yy) .* sin(9*%pi*xx) .* sin(9*%pi*yy) .^ 2;

    • Quite right Sylvestre. Good catch. The line was too long to fit on the blog so I edited te line and accidentally dropped the closing right paren. The line should be:

      Z = (16 * (xx .* yy) .* (1 – xx) .* (1 – yy) .* sin(9*%pi*xx) .* sin(9*%pi*yy)) .^ 2;

      James M

Comments are closed.