Plotting Rosenbrock’s Function with SciLab

I was looking at an interesting numerical optimization technique recently and I wanted to test the technique against a well-known numerical optimization benchmark problem. One such benchmark is called Rosenbrock’s function. It is defined as:

f(x,y) = 100(y – x^2)^2 + (1 – x)^2

Here I’m using the carat character with 2 to indicate squaring. The function has a global minimum when x = 1 and y = 1, (giving a function value of 0.0). The Rosenbrock function has an interesting shape when graphed so I set out to create an image of the graph using SciLab. SciLab is a close but not exact clone of MatLab. Here are the SciLab commands I issued to generate the image at the bottom of this post:

x1 = linspace(-2,2,100); 
x2 = linspace(-2,2,100); 
[X1,X2] = meshgrid(x1,x2); 
Z = 100*(X2-X1.^2).^2+(1-X1).^2; 
f = scf(); 
f.color_map = rainbowcolormap(64);

The first two commands create 100 numbers between -2 and +2. The meshgrid command creates 100 x 100 = 10,000 (x,y) points. The fourth command generates 10,000 Z values according to the Rosenbrok function definition. The .^ operator means square each (x,y) point, rather than square a matrix. The remaining three commands actually generate the 3D plot.


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

2 Responses to Plotting Rosenbrock’s Function with SciLab

  1. ahucuk says:

    I reviewed your ant colony optimization program. I have one question for you. I tried to reach you via email; it was unsuccesful.

Comments are closed.